Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

cannot use mixed-case string as foreach "name" att

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
liviu.gelea
Smarty Rookie


Joined: 25 Nov 2015
Posts: 16

PostPosted: Wed Dec 09, 2015 2:32 pm    Post subject: cannot use mixed-case string as foreach "name" att Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5067
Location: Hamburg / Germany

PostPosted: Thu Dec 10, 2015 5:03 am    Post subject: Reply with quote

I will check that. You can use the newer {foreach} format.

Code:
{foreach $myarray as $myitem}
   {$myitem@iteration}{$myitem}
{/foreach}
Back to top
View user's profile Send private message
liviu.gelea
Smarty Rookie


Joined: 25 Nov 2015
Posts: 16

PostPosted: Thu Dec 10, 2015 9:11 am    Post subject: Reply with quote

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
View user's profile Send private message
liviu.gelea
Smarty Rookie


Joined: 25 Nov 2015
Posts: 16

PostPosted: Thu Dec 10, 2015 12:40 pm    Post subject: another case Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5067
Location: Hamburg / Germany

PostPosted: Sun Dec 13, 2015 9:15 am    Post subject: Reply with quote

The fix is now on github in the master branch
Back to top
View user's profile Send private message
liviu.gelea
Smarty Rookie


Joined: 25 Nov 2015
Posts: 16

PostPosted: Mon Dec 14, 2015 9:41 am    Post subject: Works perfectly Reply with quote

Thanks a lot
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP