[英]How to extract an array in smarty using tpl?
大家好,我對在Smarty中提取數組有疑問。 我知道如何使用foreach,但是在提取此數組時遇到困難。
這是我的數組:
Array
(
[0] => Array
(
[category_id] => 203
[category] => Ayala Ave.
[company_id] => 2
)
[1] => Array
(
[category_id] => 291
[category] => Design
[company_id] => 2
)
)
在我的聰明模板中,我有這個
{foreach from=$product.category_description item=description1}
{$description1}
{/foreach}
我首先需要提取的是索引0中的類別,即AyalaAve。
我怎樣才能做到這一點?
您可以在Smarty中使用“。”訪問數組。
{foreach from=$product.category_description item=description1}
{$description1.category}
{/foreach}
嘗試這個 :
{$yourarray[0].category}
要么
{foreach from=$product.category_description item=description1 name=description1}
{if $smarty.foreach.description1.first}{$description1.category}{/if}
{/foreach}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.