|
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 |
h1nebefe Smarty Rookie
Joined: 20 Apr 2003 Posts: 7
|
Posted: Thu Apr 24, 2003 7:33 pm Post subject: Bug with arrays? |
|
|
I have an array assigned from php in the format:
$myarray[1] = 10
$myarray[2] = 20
Etc.
In my template, I try to access the array as follows:
{section name=pages loop=$pagecount}
{$myarray[$smarty.section.pages.iteration]}
{/section}
However, this didn't work, so I looked in the compiled template - There was the error:
Smarty was creating:
$this->_tpl_vars['myarray'][$this->_tpl_vars['smarty.section.pages.iteration']]
Instead of:
$this->_tpl_vars['myarray'][[$this->_sections['pages']['iteration']]
It looks like the $smarty reserved variable is being parsed incorrectly or there is an error with nesting non-associative and associative arrays. Is this documented? What should I do? |
|
Back to top |
|
Wom.bat Smarty Pro
Joined: 24 Apr 2003 Posts: 107 Location: Munich, Germany
|
Posted: Thu Apr 24, 2003 7:43 pm Post subject: |
|
|
no, this is not a bug. the syntax you use is just not supported
you should rather do
Code: | {foreach from=$items item="item"}
{$item}
{/foreach} |
you can also supply a "name" attribute to {foreach} and then use the same functionality as provided with sections ({$smarty.foreach.name.iteration}, {$smarty.foreach.name.last} etc). this is NOT documented by the way... |
|
Back to top |
|
h1nebefe Smarty Rookie
Joined: 20 Apr 2003 Posts: 7
|
Posted: Thu Apr 24, 2003 7:46 pm Post subject: |
|
|
But I am not looping through an array. I am using my section to do something a number of times. |
|
Back to top |
|
dthought Smarty Regular
Joined: 21 Apr 2003 Posts: 55 Location: Melbourne, Australia
|
Posted: Sun Apr 27, 2003 9:43 am Post subject: |
|
|
I think you might be trying to needlessly complicate the way you do your section loops.
Is this what you're after?
{section name=pages loop=$myArray}
{$myArray[pages]}
{/section} |
|
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
|