|
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 |
hagman Smarty Rookie
Joined: 18 Apr 2003 Posts: 10 Location: Östersund, Sweden
|
Posted: Fri Apr 18, 2003 2:30 pm Post subject: Loops and Vars |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Apr 18, 2003 3:20 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Apr 18, 2003 4:05 pm Post subject: |
|
|
In your foreach loop, you just wrote over what was assigned to $lang. Use a different varname for the loop. |
|
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
|