[Phplib-users] Templates -- lists vs. rows
Brought to you by:
nhruby,
richardarcher
From: Matthew L. <lei...@ma...> - 2002-11-05 19:54:21
|
Hi, Say I have an array of link names and URLs that I want to put into an HTML page. If I want a list, it's easy enough. The template contains <!-- main.tpl --> <ul> <!-- BEGIN each_link --> <a href="{URL}">{TEXT}</a> <!-- END each_link --> </ul> and the code is $template->set_block('main','each_link','EACH_LINK'); foreach ($links as $url => $text) { $template->set_var('URL',$url); $template->set_var('TEXT',$text); $template->parse('each_link','EACH_LINK',true); } $template->parse('main','MAIN'); $template->print('MAIN'); But what if instead of a list I want this? [ <a href="url1">text1</a> | <a href="url2">text2</a> | ... | <a href="urln">textn</a> ] There should be a way to write the two templates so that a single snippet generate both. The problem is the divider, which comes after each link but the last. How can this be done while keeping all presentation data in the templates and all logic in the PHP script? Any thoughts are appreciated. --Matt -- ---------------------------------------------------------------- Matthew Leingang http://www.math.rutgers.edu/ Rutgers University lei...@ma... Department of Mathematics "This signature needs no quote." |