Array
(
[0] => Array
(
[product_id] => 49
[thumb] => http://192.168.0.101/user1/OPC_Fabish3.0/upload/image/cache/catalog/demo/banners/Productimage-278x355.jpg
[rollover_thumb] => http://192.168.0.101/user1/OPC_Fabish3.0/upload/image/cache/catalog/demo/banners/Productimage-278x355.jpg
[name] => tulip lamp family
[description] => Samsung Galaxy Tab 10.1, is the world’s thinnest tablet, measuring 8.6 mm thickness, running w..
[price] => $241.99
[special] =>
[tax] => $199.99
[rating] => 0
[href] => http://192.168.0.101/user1/OPC_Fabish3.0/upload/index.php?route=product/product&product_id=49
[model] => SAM1
)
)
这是products
中的PHP
数组。
在twig中,我使用以下代码获取值:
{% for j in 0..(products|length) %}
<a href="{{ products.j[href] }}"></a>
{% endfor %}
但是我没有得到任何结果。
答案 0 :(得分:2)
我想是:
<a href="{{ products[j]['href'] }}"></a>
// or
<a href="{{ products[j].href }}"></a>
或更简单:
{% for product in products %}
<a href="{{ product.href }}"></a>
{% endfor %}