|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
infira Smarty n00b
Joined: 28 Oct 2011 Posts: 2
|
Posted: Tue Nov 01, 2011 8:54 am Post subject: Doubble loop to one to increase perfomace |
|
|
Old way
Prepare data in php
Code: | <?php
class myClass
{
public function parseData($assignName,$ID)
{
$data = dbQuery("SELECT * FROM articles ID = $ID");
$list = array();
if (is_resource($data))
{
while ($Row = mysql_fetch_object($data))
{
$Row->link = fixLink($Row->link);
// do some more cool stuff here
$list[] = $Row;
}
}
$smarty->assign($assignName,$list);
}
}
$class = new myClass();
$smarty->assign("MyClass",$class);
?>
|
And in the template file i do this
Code: | {$MyClass->setData("parsedData",41)}
{foreach from = $parsedData item = row}
{$row->link}
{/foreach} |
If i have a large amount of data in this way data is looped twise.
how do decrease foreach to one.
Perhaps something like this
Code: | {data ID = 41 item = row}
{$row->link}
{/data} |
And in the block is compiled smarty tempalte source and data in the same time, is it possible |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|