RE: [SMARTY] for / while loop in Smarty
| From: | Sims, Benjamin | Date: | Tue, 16 Dec 2003 17:21:46 +0000 |
| Subject: | RE: [SMARTY] for / while loop in Smarty | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-10703@lists.php.net to get a copy of this message | ||
Thanks, that was what I was looking for. Here is the code, for posterity:
{section name=menu loop=$menu}
{section name=level loop=$menu[menu]}
{$menu[menu][level].name|indent:$smarty.section.menu.iteration:" "}
{/section}
{/section}
Ben
-----Original Message-----
From: Daniel Cummings [mailto:dan@dbmscan.com]
Sent: 16 December 2003 16:35
To: Sims, Benjamin; smarty-general@lists.php.net
Subject: Re: [SMARTY] for / while loop in Smarty
On 12/16/03 6:28 AM, "Sims, Benjamin" <B.Sims@unesco.org> wrote:
> Now, since this is a section loop I have .iteration which will give the
> number of spaces to print. However, I can't work out how to do:
>
> for($iteration){
>
> print_space
>
> }
>
> Any ideas as to the best way to go about this?
Try indent variable modifier with the .iteration as param 1.
{section name=menu loop=$textarray}
{$textarray[menu]|indent:$smarty.section.menu.iteration:"___"}<br>
{/section}
I suggest using the triple underscore as param 2 for testing so you can see
clearly the result, but then just switch it to space (the default) or tab or
whatever you need to get the desired effect.
Remember, plugin dir must be specified to gain access to variable modifiers
like indent. That tripped me up in one project.
For example: (it is very unlikely that this command will work "as is" on
your system, modify paths and object var "$this" to suit.)
$this->plugins_dir = '/usr/local/smarty/libs/plugins';
Put it in your setup file or if you don't use a setup file, in your init
steps. It will explicitly tell smarty to use the default location to find
plugins. I know there is supposed to be a default plugin location which
points to this dir, but variable mods didn't work for me until I told my app
exactly where to get them.
HTH,
dan