View previous topic :: View next topic |
Author |
Message |
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Thu Sep 18, 2003 2:35 pm Post subject: Q about iteration in sections |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Sep 18, 2003 3:21 pm Post subject: |
|
|
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 |
|
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Thu Sep 18, 2003 9:08 pm Post subject: |
|
|
1. Aaaaarghhh 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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Sep 18, 2003 9:16 pm Post subject: |
|
|
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 |
|
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Thu Sep 18, 2003 9:18 pm Post subject: |
|
|
Hmm, gotta look at that, then. Thanks! |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Sep 18, 2003 9:24 pm Post subject: |
|
|
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 |
|
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Thu Sep 18, 2003 9:35 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Sep 18, 2003 9:44 pm Post subject: |
|
|
hmm
{foreach from=$Object->itemList.imageList key=numberOfImage value=image}
... use {$numberOfImage} and {$image} ....
{/foreach}
??? |
|
Back to top |
|
|