如何在 Smarty 中访问数组内的哈希



只是一个简单的问题,我无法通过谷歌找到。我有一个数组,其中一个元素有一个哈希。我想知道如何访问该哈希,特别是金额:

这是数组

[tsh_promotion_details] =>
[{"id":"1","amount":10,"type":"product.percentage","product_price":69.9,"product_quantity":1}]

{$position.attributes.tsh_promotion_details|@print_r}我收到这个:

[{"id":"1","amount":10,"type":"product.percentage","product_price":69.9,"product_quantity":1}]

但我不知道热访问金额。感谢帮助。

我最终得到了它。如果有人在这里遇到类似的问题,解决方案:基本上它是数组中的嵌套 json。通过Smarty的Json_decode,您可以将其转换为数组,并像通常一样打印出来。

{assign var=foo value=$position.attributes.tsh_promotion_details|json_decode}

最新更新