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

sections with 2-dimensional 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
rado
Smarty n00b


Joined: 14 Jul 2003
Posts: 1

PostPosted: Mon Jul 14, 2003 5:31 pm    Post subject: sections with 2-dimensional arrays Reply with quote

Hi, I've read a lot threads about Smarty sections and arrays but couldn't find my problem.
I have 2 nested sections:
{section name="sm_row" loop=$rownum} and {section name="sm_col" loop=$rowanz[$smarty.section.sm_row.index]}
my array is of the style: sitemap[x][y].item
I try to access this array in smarty like this:
{$sitemap[$smarty.section.sm_row.index][$smarty.section.sm_col.index].sub2}
Don't get any results. Not even an error. Just nothing.
I have other templates with single sections and single arrays same style, they work pretty well.
Thx for any hints, Rado
Back to top
View user's profile Send private message
Enquest
Smarty Regular


Joined: 14 May 2003
Posts: 79

PostPosted: Mon Jul 14, 2003 6:06 pm    Post subject: Reply with quote

Ok I could be wrong but I''m sure Boots or somebody will correct me..


I think the problem must be the second section. That would be the place wher I would be looking. Maybe how the loops work
Could you eleborate how this array look like. Maybe print_r
_________________
-----------------------
Learning my self by trying to help others
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Jul 14, 2003 9:48 pm    Post subject: Reply with quote

Me correct someone? Wink

Actually, I'd just try to side-step this issue entirely by switching to foreach loops or using intermediate assignments. Sections can be a pain, especially when nested. Things like [$smarty.section.sm_row.index] make me queasy.

ASIDE:
Sections are sometimes a little more managable if you use the (I believe depracated, oh horrors) little-known % syntax (eg. [%sm_row.index%]) but unfortunately, that is not really a *recommended* feature. But I'm no snitch and as I'm not privvy to the reasons it has been deprecated, I can't see why it shouldn't at least be mentioned since it is still supported--for now.


I didn't test the issue, so I can't give a more definitive answer--sorry!

HTH
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Mon Jul 14, 2003 10:46 pm    Post subject: Reply with quote

to me (knowing php's foreach) foreach is much easier to grasp than section, but anyway:

{$sitemap[$smarty.section.sm_row.index][$smarty.section.sm_col.index].sub2}
is not working, for reasons unknown to me, but it boils down to
{$sitemap[sm_row][sm_col].sub2} anyway.

i didn't run it, but it looks much better regarding the php-code that smarty generates for the latter. Smile
Back to top
View user's profile Send private message Send e-mail 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