开发者

Smarty Concatenation

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 == $myva开发者_运维百科r2.a+$v}
    match
    {else}
    no match    
    {/if}
{/foreach}

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

Thanks


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}


I think the problem may be the approach. You should include your logic in the PHP code, not in the template.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜