简体   繁体   中英

Smarty array in tpl

In PHP file I have an array when print_r looks like array([response_code] => 100, [products[0][price]] => 149.00 [products[0][name]] => 'Blah blah.....') and it is assigned to by this:

$smarty->assign('order_details', $order_details); //$order_details is the array above.

Now on template, I can display response_code by:

{$order_details.response_code}

But how can I display the product name? I tried:

  1. {$order_details.products[0][name]}
  2. {$order_details.products[0].name}
  3. {$order_details.products.0.name}

But nothing worked. Please some one help...

Try this it will work :

$smarty->assign('order_details', $order_details); //$order_details is the array above.

Now on template, I can display by fetching array values like this:

{section name=i loop=$order_details}

{$order_details[i].name}

{/section}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM