tags:

views:

437

answers:

1

Hi i am trying to do concatenation in smarty. Here is an example of how i would like to use the code. The php assigns

$smarty->assign('myvar',array(1,5,6,4));
$smarty->assign('myvar2',array('a1'=>1,'a2'=>2,'a3'=>3,'a4'=>4));

And the template page

{foreach from=$myvar item=v}
    {if $v == $myvar2.a+$v}
    match
    {else}
    no match    
    {/if}
{/foreach}

This sould write out 'match' two times and 'no match' two times.But instead writes match four times which makes no sense to me.

Thanks

+1  A: 

Interpolate the key before using it:

{foreach from=$myvar item=v}
{assign var="idx" value="a"|cat:$v}
{if $v == $myvar2.$idx}
    match
{else}
    no match
{/if}
{/foreach}
scribble
thanks that worked
andrew