Smarty loop overhead question

Discussion corner for Developers of Serendipity.
Post Reply
User avatar
Don Chambers
Regular
Posts: 3636
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Smarty loop overhead question

Post by Don Chambers » Thu Jan 08, 2015 10:38 pm

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?

User avatar
onli
Regular
Posts: 2252
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Smarty loop overhead question

Post by onli » Fri Jan 09, 2015 1:51 am

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.

User avatar
Don Chambers
Regular
Posts: 3636
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: Smarty loop overhead question

Post by Don Chambers » Fri Jan 09, 2015 6:42 pm

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

Post Reply