Twig 逐枝循环迭代

Twig 逐枝循环迭代,twig,Twig,这是我在PHP中的产品数组。 在twig中,我使用以下代码获取值: 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

这是我在
PHP
中的
产品
数组。 在twig中,我使用以下代码获取值:

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
        )
)
{%j在0..(产品|长度)%}
{%endfor%}
但是我没有得到任何结果。

我想是这样的:

{% for j in 0..(products|length) %}
    <a href="{{ products.j[href] }}"></a>
{% endfor %}

//或
或者更简单:

<a href="{{ products[j]['href'] }}"></a>
// or
<a href="{{ products[j].href }}"></a>
{%用于产品中的产品%}
{%endfor%}

U确实想引用第一个
href
。现在<代码> Tigg < /代码>将考虑它是(n个未定义)变量不工作。{%for products%}{%endfor%}将绝对有效,但我想调整数组,因此我必须手动迭代products数组。然后
products[j]。href
那么你做错了什么。看电视。别忘了你需要减去一个长度,否则你会在你的数组中达到一个超出范围
{% for product in products %}
    <a href="{{ product.href }}"></a>
{% endfor %}