Re: section title block

From: Date: Sun, 25 Feb 2001 22:15:30 +0000
Subject: Re: section title block
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-222@lists.php.net to get a copy of this message
Sergey Egorov wrote: > > AZ> I cannot promise this will get implemented because it would be very tough > AZ> to do due to the way parsing is done. > > What is the problem? It seems very strait for me. > Smarty finds template tags, and replaces them with PHP tags. So {section ...} gets converted to <?php if(...) ?> and {/section} gets converted to <?php endif(); ?> (this isn't technically exact, but in a nutshell...) So, that means you have to have some kind of identifier in the {section_header} tag to identify which section it is for. Smarty does not keep track of template tags relative to other template tags (technical and performance reasons.) You have to have some kind of indicator in the tag so Smarty understands what section the tags correspond to. You also can't have open ended tags that affect output around them, so a closing tag is needed. example: {section name=$mystuff loop=$data} {section_header name=$mystuff loop=$data} .. header data .. {/section_header} .. row data .. {/section_footer name=$mystuff loop=$data} .. footer data .. {/section_footer} {/section} But then what are you gaining? You may as well use {if} tags. BUT, here comes an entirely different approach... how about we add a boolean parameter to the {include ...} statement, making the include conditional. for example: {section name=mystuff loop=$data} {include file="section_header.tpl" show=%mystuff.first%} {* put section rows here *} {include file="section_footer.tpl" show=%mystuff.last%} {/section} We'll add to Smarty the entities %section.first% and %section.last%, being true/false depending on the section iteration. We'll also add the boolean flag "show" (or whatever name is decided) to the include function, default being true of course. This solves several things, first that come to mind: * still understandable syntax to designers * modularizes the template, so section headers/footers are reusable (can pass parameters, whatever) * We don't add new syntax to the template engine, keeping smarty a bit leaner * very easy to implement :-) -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

« previous php.smarty.general (#222) next »