|
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 |
liviu.gelea Smarty Rookie
Joined: 25 Nov 2015 Posts: 16
|
Posted: Wed Dec 09, 2015 2:32 pm Post subject: cannot use mixed-case string as foreach "name" att |
|
|
Hello. The following code outputs "a b 1a 2b" instead of expected "1a 2b 1a 2b"
Code: |
[%assign var=myarray value=array("a", "b") %]
[%foreach from=$myarray key="mykey" item="myitem" name="camelCase" %]
[% $smarty.foreach.camelCase.iteration %][% $myitem %]
[%/foreach%]
[%foreach from=$myarray key="mykey" item="myitem" name="lowercase" %]
[% $smarty.foreach.lowercase.iteration %][% $myitem %]
[%/foreach%]
|
The problem seems to be caused by the fact that foreach cannot use uppercase characters inside the "name" attribute. if I set the name to anything containing just lowercase characters everything works fine.
Thanks for your support.
ps. sorry for weird delimiters. It's safer to just copy-paste code as-is.
pps. I'm using the latest smarty3 version on github. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Dec 10, 2015 5:03 am Post subject: |
|
|
I will check that. You can use the newer {foreach} format.
Code: | {foreach $myarray as $myitem}
{$myitem@iteration}{$myitem}
{/foreach} |
|
|
Back to top |
|
liviu.gelea Smarty Rookie
Joined: 25 Nov 2015 Posts: 16
|
Posted: Thu Dec 10, 2015 9:11 am Post subject: |
|
|
I can try the newer format and in fact I use it for new code. But there are 120 instances of mixed-case .iteration uses in my legacy code.
I think I have a script i used for @first and @last replacements around here but i don't trust it much and I still had to report this out of professional courtesy.
Thanks. |
|
Back to top |
|
liviu.gelea Smarty Rookie
Joined: 25 Nov 2015 Posts: 16
|
Posted: Thu Dec 10, 2015 12:40 pm Post subject: another case |
|
|
Hi. the same thing happens inside the "section" tag for the name attribute. This seems to be a problem with the name attribute
Code: |
[%section loop=$USER.Groups name=uGroup%]
<option value="[%$USER.Groups[uGroup].IdGroup%]">[% $USER.Groups[uGroup].GroupName|toHTML %]</option>
[%/section%]
|
This was "fixed" by changing "uGroup" to lowercase: (ugroup) |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Dec 13, 2015 9:15 am Post subject: |
|
|
The fix is now on github in the master branch |
|
Back to top |
|
liviu.gelea Smarty Rookie
Joined: 25 Nov 2015 Posts: 16
|
Posted: Mon Dec 14, 2015 9:41 am Post subject: Works perfectly |
|
|
Thanks a lot |
|
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
|