Divya Priya
Divya Priya

Reputation: 13

How to display the nested foreach values in smarty

I need to display the nested for-each loop values in smarty.

I have the array like


Array ( 
     [err] => 0 
     [code] => 0 
     [msg] => Success 
     [retval] => Array ( 
         [0] => Array ( 
              [id] => 8 
              [thread_id] => 8 
              [body] => Hi test message 
              [priority] => 1 
              [sender_id] => 11 
              [cdate] => 2015-06-01 12:26:55 
              [status] => 1 
              [subject] => Hi 
              [user_name] => soniya kaliappan 
         ) 
     ) 
)

how can I get the retval['body'] value in smarty . Please help me .

Upvotes: 0

Views: 770

Answers (1)

Sougata Bose
Sougata Bose

Reputation: 31749

Simply run the foreach inside another foreach -

{foreach from=$yourarray item=loopVal}
  {foreach from=$loopVal.retval key=retval item=retVal}
    {$retVal.body}
  {/foreach}
{/foreach}

Or there will be only one array inside retval then -

{foreach from=$yourarray item=loopVal}
    {$loopVal.retVal.0.body}
{/foreach}

Upvotes: 1

Related Questions