Page 1 of 1

Smarty loop overhead question

Posted: Thu Jan 08, 2015 9:38 pm
by Don Chambers
I have a need for a simple loop in a template. Smarty 3 (s9y >=1.7) has the function {for}, ie {for $var=$start to $end} ... but smarty 2 (s9y < 1.7) doesn't have that. Closest I could find was {section}, as in {section name=whatever loop=$end}, which also works in smarty 3.

Is it worth doing a conditional test on $head_version, then using the corresponding function (for > 3, section < 3), or just live with {section} since it works in both? Is there an overhead impact?

Re: Smarty loop overhead question

Posted: Fri Jan 09, 2015 12:51 am
by onli
Do you really want to target version before s9y 1.7? They are not safe to use anymore. In my eyes, for every project with not very specific requirements you should just use smarty 3 syntax.

Otherwie we would could try to look at the generated php code, but then the code would be already there and a short benchmark probably the best way to go.

Re: Smarty loop overhead question

Posted: Fri Jan 09, 2015 5:42 pm
by Don Chambers
I looked at the generated php code in templates_c. The {section} function generates considerably more code... approximately 20 lines of code compared to {for} which generated only 4 lines of code. Guess I will go with {for} and have a template requirement of >= 1.7