Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print an array in smarty?

I have an array:

 $team_details = Array ( [id] => 1 [name] => doge_finder [total_rewards] => 52.00524500 [desciption] => team is only of doge miners [created_by] => 20 );

/* assigning to a smarty template */
$smarty->assign("team_record", $team_details);          
$smarty->display($tpl);

In template file:

{foreach from= $team_record key=team item=trecord}
{$trecord[$key].name}
{/foreach}

In result output must be "doge_finder", but I got first initial character of each record in array ie. "1 d 5 t 2"

how can I resolve this problem?

like image 312
codeBYmahesh Avatar asked Dec 25 '22 11:12

codeBYmahesh


1 Answers

we can Use {$team_record|print_r} to dsiplay whole Array in the smarty file.

Output:

 Array
 (
    [id] => 1                  
    [name] => doge_finder
    [total_rewards] => 52.00524500
    [desciption] => team is only of doge miners
    [created_by] => 20
)

we can Use below Code to iterate the Array in Smarty file

{foreach from=$team_record key=arrayIndex item=trecord}
   {$arrayIndex}: {$trecord}
   <br>
{/foreach}

Output :

       id: 1

       name: doge_finder

       total_rewards: 52.00524500

       desciption: team is only of doge miners

       created_by: 20 
like image 85
Jah Yusuff Avatar answered Dec 28 '22 05:12

Jah Yusuff