Re: Limiting the section loop
| From: | Anders Janson | Date: | Thu, 21 Jun 2001 10:28:47 +0000 |
| Subject: | Re: Limiting the section loop | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-926@lists.php.net to get a copy of this message | ||
hans@linux.gelrevision.nl wrote:
> On 21-Jun-01 Anders Janson wrote:
>
> > A much neater way would be to write something like:
> > {section name=foo loop=$bar limit=7}
>
> If you have a resultset with over 10k of rows it will have to be passed to
> Smarty. Afaik a limit within (for instance) a dbserver is cheaper.
Hehe... you're absolutely right! I wouldn't dream of passing 10k rows to
Smarty :-)
No, of course my resultset is already limited to a reasonable size.
But you did not understand me 100% I think....
<example>
Lets say we are working with a guestbook, discussion board or something. The
data set selected from the db could be "todays postings", and we have for
example 20 postings today (could also be limited to [something] in the db
query).
On one page I could show all postings, on another I could show the 5 newest.
The dataset would always contain all posts from today, sorted by time. My
code would be simple - get the posts from today. The rest is up to the
presentation (read: template).
</example>
The code could structured like this (much simplified):
1. Get db data, assign to Smarty
2. Select a template, based on some obscure criteria :-)
3. Display.
This way the code/logic (in step 1) becomes totally isolated from the
presentation. In step 2, I could have a number of different templates to try
out different layouts, themes etc. In some layouts perhaps 5 rows from the
dataset looks better, is more logical or whatever. On another perhaps 3 is
better.
I want the template to decide how much to display. A limit attribute would
come in handy.
/Anders Janson