Re: Arguments for Smarty
| From: | Monte Ohrt | Date: | Fri, 07 Dec 2001 15:45:50 +0000 |
| Subject: | Re: Arguments for Smarty | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2198@lists.php.net to get a copy of this message | ||
Pablo wrote:
>
> For example, coming from the PHPLIB templates we used to use, the way you
> show database results is to assign each record one at a time using blocks.
> So you are rendering each line of the result set and that means that
> resource requirements are significantly less (to be fair, it depends on how
> you handle the templates and parsing. A bad programmer could get back to
> the 10,000 x 1K memory issue above). I don't see functionality from Smarty
> to do this. It seems to be an all-or-nothing proposition when you do
> sections. You need to send ALL the data to the template and it loops
> through the array. Is there some "block" type functionality that will let
> the looping happen inside the PHP file and call a smarty template per
> record? I am thinking yes, but it means you would need to render the header
> first, then the records, then the footer. ??
>
You can do several things. You can use the append() function in Smarty
to loop through your data and accumulate it row by row as you query your
database (although it is a bit more efficient to assign everything in
one go). It is up to you to grab the subset of data you need for the
template.
If you really like the PHPLib way of appending and accumulating template
blocks, by all means go ahead! You can do it, we just don't encourage
the practice or show examples. Something like this:
index.php
---------
// query db and get results
while($sql->next) {
$smarty->assign($sql->record);
$rowdata .= $smarty->fetch("row.tpl");
}
$smarty->assign("rowdata",$rowdata);
$smarty->display("index.tpl");
row.tpl
-------
<tr><td>{$var1}</td><td>{$var2}</td><td>{$var3}</td></tr>
index.tpl
---------
{include file="header.tpl"}
<table>
{$rowdata}
</table>
{include file="footer.tpl"}