【发布时间】:2015-05-31 17:38:03
【问题描述】:
刚开始使用树枝模板,我遇到了一个问题。我有一个数组,我正在循环并从中提取数据,在这个数组中我有另一个我需要访问的数组(图像),问题是我似乎无法让它工作。
这是我的提要
0 =>
array (size=8)
'id' => int 1
'url' => string 'http://localhost' (length=16)
'image' => string '8cgbfenx2n1.png' (length=15)
'type' => string 'image' (length=5)
1 =>
array (size=10)
'id' => int 17
'images' =>
array (size=3)
0 => string 'xjv5y4asev2.png' (length=15)
1 => string 'kwwss8f6r34.gif' (length=15)
2 => string '68yfnckk3c5.png' (length=15)
'text' => string 'text' (length=4)
'type' => string 'article' (length=7)
然后我像这样循环访问并访问
{%- if feed is not empty -%}
{% for feedItems in feed %}
<!-- article -->
{% if feedItems.type == 'article' %}
<!-- image -->
<div class="gridTile-article-image">
{% for image in feedItems.images %}
{{ image }} <br />
{% endfor %}
</div>
{% endif %}
{% endfor %}
{% endif %}
这不会抛出错误但也不会输出任何东西,任何人有任何想法必须实现这一点?
谢谢!
【问题讨论】:
-
没有内循环可以工作吗?
-
无需检查
feed是否为空。使用Twig的for循环,您可以执行{% else %} No feed {% endfor %}。 -
是的,没有内部循环也可以正常工作,所以我可以返回数组中的内容,我只是无法访问该数组中的数组。啊,谢谢 D4V1D!
标签: php arrays symfony twig templating