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

问题描述 投票:0回答:1

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

这是阵列

[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}]

但我不知道如何获取金额。感谢帮助。

arrays hash smarty
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.