Optional Sections

From: Date: Tue, 24 Feb 2004 08:59:44 +0000
Subject: Optional Sections
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11015@lists.php.net to get a copy of this message
Hi, I have decided to port the template engine used in my application (http://egs.sourceforge.net) to Smarty. However I am having trouble working out how to make a section optional and repeatable. For example in PEAR Temaplate you can have the following: <!-- BEGIN block --> <tr> <td>{someValue}</td> </tr> <!-- END block --> Now if you don't assign anything to {someValue} anywhere in the template then this block is not displayed. However, if you wanted to you could call this block several times and have more than one table row. Now I have the following in Smarty that I am using as a test: {foreach key=key item=item from=$menu_options} <tr> <td class="submenu">{$item}</td> </tr> {/foreach} However whenever I call assign() I only ever get the last call to it showing in the template. Is there a way to do this in smarty? I ideally want to scale it too so that I could do the following <!-- first section --> <tr> <td colspan="2">{$someTitle}</td> </tr> <!-- second section --> <tr> <td>{$key}</td> <td>{$value}</td> </tr> <!-- end second section --> <!-- end first section --> In this example I would like to be able to put several "second sections" in the template with the "first section" as a header row. But I would like to be able to do it more than once so: <tr> <td colspan="2">Men</td> </tr> <tr> <td>Joe</td> <td>Bloggs1</td> </tr> <tr> <td>Joe</td> <td>Bloggs2</td> </tr> <tr> <td colspan="2">Women</td> </tr> <tr> <td>Jane</td> <td>Bloggs1</td> </tr> <tr> <td>Jane</td> <td>Bloggs2</td> </tr> Thanks for any help I may receive. Jake

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