Re: [SMARTY] how do [iteration - 1] in template?

From: Date: Sun, 21 Mar 2004 18:28:28 +0000
Subject: Re: [SMARTY] how do [iteration - 1] in template?
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11155@lists.php.net to get a copy of this message
On Sun, Mar 21, 2004 at 05:25:24PM +0100, Kalle wrote: > > Hello Smarties, > > I would like to use "iteration - 1" as an index in an array: > > {foreach name=val key=key item=Val from=$Row} > {if $ColNames[$smarty.foreach.val.iteration - 1] > eq $PkNames[$smarty.foreach.val.iteration - 1]} > {$Val} (*) > {else} > {$Val} > {/if} > {/foreach} > > This generates: > > Fatal error: Smarty error: [in index.tpl line 15]: syntax error: > $smarty. is an unknown reference (Smarty_Compiler.class.php, line 2031) > in C:\PHP\lib\Smarty\Smarty.class.php on line 1102 you have to assign this value to use it as an array index: {foreach name=val key=key item=Val from=$Row} {assign var=index value=$smarty.foreach.val.iteration-1} {if $ColNames[$index] eq $PkNames[$index]} {$Val} (*) {else} {$Val} {/if} {/foreach} > It works fine if I remove "- 1", or if I print it like so: > {$smarty.foreach.val.iteration - 1} > > (Smarty 2.6.2) > > I'm stuck > Kalle > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#11155) next »