[nycphp-talk] Smarty syntax: for(...)
Chris Snyder
csnyder at chxo.com
Wed Oct 22 17:45:58 EDT 2003
It is a little baffling considering all of the other functionality
packed in there. I guess for loops definitely cross the line into
application logic.
In light of the overhead that Smarty imposes on your scripts, you might
want to rethink the notion of avoiding unnecessary work in PHP-- after
all, anything that you are asking Smarty to do is eventually being done
by PHP anyway. Just because you can do something in the template, like
logic or iteration, doesn't mean that you should. Take a look at the
"compiled" code that Smarty is generating to see what I mean.
csnyder
Scott Mattocks wrote:
> I thought about doing that but I want to avoid any unnecessary work in
> my PHP if I can. I know that I could also just include PHP code in my
> template but I was hoping for something more elegant than that. It
> just baffles me that Smarty doesn't have a plain old looping structure
> that isn't tied to an array.
>
> Scott Mattocks
>
> Chris Snyder wrote:
>
>> As a hack you could make an array with the number of elements needed,
>> and use that to loop in the template.
>> Sounds ugly, I know, but you could do it in your PHP code before you
>> go to display the template, using something like:
>>
>> $loop = array();
>> for ( $i = 0; $i < max_iters; $i++ ){
>> $loop[$i] = $i;
>> }
>>
>> There's probably a more graceful way to do it, but then, there are
>> more graceful ways to template than Smarty, as we learned at last
>> month's meeting. ;-)
>>
>> csnyder
>>
>> Scott Mattocks wrote:
>>
>>> Hello,
>>>
>>> I am working with Smarty templates but I am having trouble trying to
>>> do what I want with them. I want to print a block of code a
>>> specific number of times sort of like I would do with a for() loop
>>> in PHP. I am not using values from an array so I can't use section
>>> or foreach loops. I can't find in the documentation how to turn
>>> something like this into Smarty code:
>>>
>>> for($i = 0; $i < max_iters; ++$i) {
>>> echo $i . "<br />";
>>> }
>>>
>>> Does anyone have any suggestions?
>>>
>>> Thanks
>>> Scott Mattocks
>>>
>>> _______________________________________________
>>> talk mailing list
>>> talk at lists.nyphp.org
>>> http://lists.nyphp.org/mailman/listinfo/talk
>>
>>
>>
>>
>> _______________________________________________
>> talk mailing list
>> talk at lists.nyphp.org
>> http://lists.nyphp.org/mailman/listinfo/talk
>>
>>
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
More information about the talk
mailing list