Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Loops and Vars

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
hagman
Smarty Rookie


Joined: 18 Apr 2003
Posts: 10
Location: Östersund, Sweden

PostPosted: Fri Apr 18, 2003 2:30 pm    Post subject: Loops and Vars Reply with quote

I feel really honerd to be the first poster in this forum.

It seems like Smarty dosen't end the loop correctly.

Code:

{$lang.change|capitalize}{*Works*}

{foreach from=$langs item=lang}
{$lang}
{/foreach}

{$lang.change|capitalize}{*Does Not Work*}


Code:

<?php if (count((array)$this->_tpl_vars['langs'])):
    foreach ((array)$this->_tpl_vars['langs'] as $this->_tpl_vars['lang']):
?>
<?php echo $this->_tpl_vars['lang']; ?>

<?php endforeach; endif; ?><br>
<?php echo $this->_run_mod_handler('capitalize', true, $this->_tpl_vars['lang']['change']); ?>

_________________
php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri Apr 18, 2003 3:20 pm    Post subject: Reply with quote

this isn't really a bug, but a property of the underlying foreach-loop in php.

you cannot access the variables you declared as key or item after the closing {/foreach}. they are gone.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Apr 18, 2003 4:05 pm    Post subject: Reply with quote

In your foreach loop, you just wrote over what was assigned to $lang. Use a different varname for the loop.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    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