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

Q about iteration in sections

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


Joined: 09 Sep 2003
Posts: 24

PostPosted: Thu Sep 18, 2003 2:35 pm    Post subject: Q about iteration in sections Reply with quote

Basically, what's wrong with this:

Quote:
<{section name=image loop=$item->imageList start=2}>
<img src="<{$imagePath}><{$item->imageList[<{$smarty.section.image.iteration}>]->url}>" alt="alt">
<{/section}>


$item is acquired through another section, and $imagepath is assigned somewhere.

The error:
Quote:
Fatal error: Smarty: [in test.tpl line 14]: syntax error: unrecognized tag: $item->imageList[<{$smarty.section.image.iteration (Smarty_Compiler.class.php, line 382) in /usr/some/dir/Smarty_Compiler.class.php on line 1824
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Thu Sep 18, 2003 3:21 pm    Post subject: Reply with quote

1. you can not nest smarty tags
2. i think it should read <{$item->imageList[image]->url}>

between [] are only section-names or integer numbers allowed.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cptnemo
Smarty Rookie


Joined: 09 Sep 2003
Posts: 24

PostPosted: Thu Sep 18, 2003 9:08 pm    Post subject: Reply with quote

1. Aaaaarghhh Smile Bound to be fixed at some point...
2. You're right, it should be that. But I actually need the number of the iteration. Gotta find another way then...
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Thu Sep 18, 2003 9:16 pm    Post subject: Reply with quote

you mean the "number of the iteration" is the "loop-value"+1 ?
why not use foreach? the "key" there would always way be the key in the $item-imageList array.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cptnemo
Smarty Rookie


Joined: 09 Sep 2003
Posts: 24

PostPosted: Thu Sep 18, 2003 9:18 pm    Post subject: Reply with quote

Hmm, gotta look at that, then. Thanks!
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Thu Sep 18, 2003 9:24 pm    Post subject: Reply with quote

grmpf, i just re-read your original post: sth. like "start=2" is not available in {foreach}. you'll have to workaround that with "{if foreach.name.iteration>=2}...{/if}" or pass more smarty-suitable data to template IMHO. (just random thoughts - i don't know the big picture of your app here)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cptnemo
Smarty Rookie


Joined: 09 Sep 2003
Posts: 24

PostPosted: Thu Sep 18, 2003 9:35 pm    Post subject: Reply with quote

It's something like this:

$Object->itemList[0] = $Object->itemList['foo'] = $value;
...
$Object->itemList[n] = $Object->itemList['bar'] = $value;

So, a 'regular' and associative array with stuff. But also,

$Object->itemList[n+1] = $Object->itemList['imageList'] = "an array of Image objects" :

$imageList[0][0] = $imageList[0]['somevar'] = 'foo'
$imageList[n][x] = $imageList[n]['othervar'] = 'bar'

So, I need the index on $imageList _and_ the index on $itemList to do something with a specific image...
See also: http://www.superinfinite.com/meuk/iteration.html
That page was created with a lil' debug class I wrote, see http://www.superinfinite.com/v10/index.php?i=337
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Thu Sep 18, 2003 9:44 pm    Post subject: Reply with quote

hmm

{foreach from=$Object->itemList.imageList key=numberOfImage value=image}
... use {$numberOfImage} and {$image} ....
{/foreach}

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