Re: Limiting the section loop
| From: | Andrei Zmievski | Date: | Thu, 21 Jun 2001 15:05:36 +0000 |
| Subject: | Re: Limiting the section loop | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-931@lists.php.net to get a copy of this message | ||
On Thu, 21 Jun 2001, Anders Janson wrote:
> Hi !
>
> A new attribute "limit" (or whatever) for the template sections would be
> nice.
> My application presents data using several Smarty templates. One
> template might display all data items, whereas another template uses
> only the first 5 or so. I don't want to bother my application code with
> these presentation details, of course, so I want to put the loop
> restrictions in the templates.
>
> Using "if" statements to check if the loop count is above my limit value
> works, but makes the templates really ugly. It means putting code in the
> presentation, and I prefer to keep that to a minimum.
>
> A much neater way would be to write something like:
> {section name=foo loop=$bar limit=7}
>
> And for compatibility, "limit" should be optional, with a default of
> "all".
You can just specify the limit directly in the loop:
{section name=foo loop=7}
...
{/section}
-Andrei
* "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis *