problem with dynamic "array key" in smarty

View: New views
3 Messages — Rating Filter:   Alert me  

problem with dynamic "array key" in smarty

by rs_satya :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I need to send an array value as a key to another array dynamically in a template.
pls . Help me.

the sample code is as follows:

{foreach name=outer item=hno key=key from=$hoas}
<tr>
<td>
{$hno.sno} //OK

{$be[{$hno.sno}]} //I tried like this -- Wrong

// Here I need to send this {$hno.sno} value as a key to {$be[]} associative array.

</td>
</tr>
{/foreach}

Re: problem with dynamic "array key" in smarty

by Peggy Schatz | screen-card.design :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

try

{$be.$hno.sno}

even though I can't figure out where .sno comes from...


The following works and puts out the desired values of $be:

{foreach name=outer item=hno key=key from=$hoas}
<tr>
<td>
{$be.$hno}
</td>
</tr>
{/foreach}

and:

$be=array('bli'=>1,'bla'=>2,'blu'=>3,'blo'=>4);
$hoas=array('test1'=>'bli','test2'=>'bla','test3'=>'blo','test4'=>'blu');
$smarty->assign('hoas',$hoas);
$smarty->assign('be',$be);

rs_satya schrieb:

> I need to send an array value as a key to another array dynamically in a
> template.
> pls . Help me.
>
> the sample code is as follows:
>
> {foreach name=outer item=hno key=key from=$hoas}
> <tr>
> <td>
> {$hno.sno} //OK
>
> {$be[{$hno.sno}]} //I tried like this -- Wrong
>
> // Here I need to send this {$hno.sno} value as a key to {$be[]} associative
> array.
>
> </td>
> </tr>
> {/foreach}

--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: problem with dynamic "array key" in smarty

by Ken Snyder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Are you looking for

{$be[$hno.sno]}

?

rs_satya wrote:

> I need to send an array value as a key to another array dynamically in a
> template.
> pls . Help me.
>
> the sample code is as follows:
>
> {foreach name=outer item=hno key=key from=$hoas}
> <tr>
> <td>
> {$hno.sno} //OK
>
> {$be[{$hno.sno}]} //I tried like this -- Wrong
>
> // Here I need to send this {$hno.sno} value as a key to {$be[]} associative
> array.
>
> </td>
> </tr>
> {/foreach}
>  

--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php