|
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 |
altendew Smarty Rookie
Joined: 07 Mar 2008 Posts: 19
|
Posted: Tue Jan 10, 2012 4:46 am Post subject: Smarty 3.1.7 for loop bug |
|
|
I noticed a bug with the for loop.
The following works
{for $i = 1000; $i >= 1; $i --}
The following does not work
{for $i = 1000 to 1}
The for loop does not support going backwards when just specifying "to" |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jan 10, 2012 2:54 pm Post subject: |
|
|
try with step=-1 |
|
Back to top |
|
altendew Smarty Rookie
Joined: 07 Mar 2008 Posts: 19
|
Posted: Tue Jan 10, 2012 3:27 pm Post subject: |
|
|
That worked, but if that is missing should it be expected behavior to work that way?
This use to work in the Smarty3.0rc3 and I had to change around on a lot of websites to get it to work. |
|
Back to top |
|
altendew Smarty Rookie
Joined: 07 Mar 2008 Posts: 19
|
Posted: Tue Jan 10, 2012 3:30 pm Post subject: |
|
|
I compared the versions and see this code was replaced:
Smarty3.0rc3
Code: |
if (isset($_attr['step'])) {
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = $_attr[step];";
} else {
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = ($_attr[to] - ($_statement[value]) < 0) ? -1 : 1;";
}
|
With this
Smarty3.1.7
Code: |
if (isset($_attr['step'])) {
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = $_attr[step];";
} else {
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = 1;";
}
|
Is there a reason the method for solving the step (if not set) was taken out and just replaced with 1? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jan 10, 2012 4:44 pm Post subject: |
|
|
uwe can probably answer this better, but it is probably a better idea to not assume a step value based on the from->to values. No different than php for(), there is no assumption of a negative step value, you have to supply it. for consistency, step is always 1 if not supplied. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Jan 13, 2012 1:12 pm Post subject: |
|
|
We did have a couple of issues determining the step value automatically from the from->to values. Remember the later can be variables.
For that reasion the code was changed. |
|
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
|