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

another array problem with section

 
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
assbach
Smarty Rookie


Joined: 21 Jun 2003
Posts: 11

PostPosted: Wed Jul 09, 2003 3:34 pm    Post subject: another array problem with section Reply with quote

hi,

i just dont get it - pardon!

look, i have arrays like

Code:
rank[0] = "alt text1";
rank[1] = "alt text2";
..
rank[5] = "alt text5";


and

Code:
$szRankVals[group][area] = array(4,3,4,0,4,3,1,4,5,0,4,2);



now i want to display the values within the template like

Code:
<td><img src="$val" alt="rank[$val]"></td>


i tried to loop through a section but it did not throw out the values...
what is the right syntax?

Code:

{section name=id loop=$szRankVals[group][area]}
<td><img src="{$szRankVals[group][area][id]}" alt=""></td>
{/section}


please help Confused
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Wed Jul 09, 2003 4:38 pm    Post subject: Reply with quote

"[]" is for section indices, "." is for hash-array dereference (consult the fine smarty-manual if unsure). so maybe what you want is:

loop=$szRankVals.group.area and {$szRankVals.group.area[id]}
Back to top
View user's profile Send private message Send e-mail Visit poster's website
assbach
Smarty Rookie


Joined: 21 Jun 2003
Posts: 11

PostPosted: Thu Jul 10, 2003 7:44 am    Post subject: Reply with quote

it's a simple as that?!
thanks a lot, it works!
Back to top
View user's profile Send private message
assbach
Smarty Rookie


Joined: 21 Jun 2003
Posts: 11

PostPosted: Thu Jul 10, 2003 10:14 am    Post subject: Reply with quote

one problem left which i couldnt find any help in the doc about...

there also is the first array $rank
with which i want to assign the alt attribute in the img tag.

i need {$szRankVals.group.area[id]} within the $Rank[ ] brackets....
you know?

this does not work!
{$rank[$szRankVals.group.area[id]]}
or
{$rank[$szRankVals.group.area.id]}

what is the way?
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Thu Jul 10, 2003 10:31 am    Post subject: Reply with quote

you have to assign an intermediate value to get this done with smarty. sth like:

Code:
{assign var=area value=$szRankVals.group.area[id]}
{$rank[$area]}
Back to top
View user's profile Send private message Send e-mail Visit poster's website
assbach
Smarty Rookie


Joined: 21 Jun 2003
Posts: 11

PostPosted: Thu Jul 10, 2003 10:40 am    Post subject: Reply with quote

this is what i was looking for....
thanks again!!!!! Very Happy
Back to top
View user's profile Send private message
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