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

Bug with arrays?

 
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 -> General
View previous topic :: View next topic  
Author Message
h1nebefe
Smarty Rookie


Joined: 20 Apr 2003
Posts: 7

PostPosted: Thu Apr 24, 2003 7:33 pm    Post subject: Bug with arrays? Reply with quote

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
View user's profile Send private message Send e-mail
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Thu Apr 24, 2003 7:43 pm    Post subject: Reply with quote

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


Joined: 20 Apr 2003
Posts: 7

PostPosted: Thu Apr 24, 2003 7:46 pm    Post subject: Reply with quote

But I am not looping through an array. I am using my section to do something a number of times.
Back to top
View user's profile Send private message Send e-mail
dthought
Smarty Regular


Joined: 21 Apr 2003
Posts: 55
Location: Melbourne, Australia

PostPosted: Sun Apr 27, 2003 9:43 am    Post subject: Reply with quote

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
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 -> General 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