【发布时间】:2015-09-22 14:38:14
【问题描述】:
我正在做一个测试项目来学习 symfony2/twig。我要做的就是显示由位置确定的图像列表。
我正在从 Instagram 的 API 中检索这些图像的数据。 API 发回 JSON 数据。对于每张图像,都有丰富的信息。我只需要将 low_resolution 值放在图像标签中。
我知道如何使用标准 PHP 来遍历数据。但是,我不知道如何使用 TWIG 来做到这一点。我只想在图像标签中显示 low_resolution url。我得到的壁橱如下:
{% if images_array == true %}
{% for key,value in images_array %}
{{ value.link }}
{% for key,value in value.images %}
<div class="col-md-3">
<img src="{{ value.url }}" alt="" class="thumbnail img-responsive" />
</div>
{% endfor %}
{% endfor %}
{% endif %}
上面的问题是它遍历了[images]中的所有[url]而不是显示来自[low_resolution]的值
以下是从 Instagram 引入的数据的第一个索引。
Array
(
[0] => Array
(
[attribution] =>
[tags] => Array
(
[0] => dubai
)
[location] => Array
(
[latitude] => -29.854119007
[name] => ICC Durban Exhibition Centre,Durban,South Africa
[longitude] => 31.029556697
[id] => 450025614
)
[comments] => Array
(
[count] => 0
[data] => Array
(
)
)
[filter] => Normal
[created_time] => 1442931165
[link] => https://instagram.com/p/775BhjE1kn/
[likes] => Array
(
[count] => 0
[data] => Array
(
)
)
[images] => Array
(
[low_resolution] => Array
(
[url] => https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s320x320/e35/11887246_500339553458410_480642133_n.jpg
[width] => 320
[height] => 320
)
[thumbnail] => Array
(
[url] => https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e35/11887246_500339553458410_480642133_n.jpg
[width] => 150
[height] => 150
)
[standard_resolution] => Array
(
[url] => https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s640x640/sh0.08/e35/11887246_500339553458410_480642133_n.jpg
[width] => 640
[height] => 640
)
)
[users_in_photo] => Array
(
)
[caption] => Array
(
[created_time] => 1442931165
[text] => Crecimiento importante a nivel Turistico y aeroportuario en #Dubai
[from] => Array
(
[username] => joseantonio1977
[profile_picture] => https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-19/11261324_916468171759729_1477908664_a.jpg
[id] => 194601237
[full_name] => Jose Antonio Lopez Sosa
)
[id] => 1079707331921664292
)
[type] => image
[id] => 1079707329077926183_194601237
[user] => Array
(
[username] => joseantonio1977
[profile_picture] => https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-19/11261324_916468171759729_1477908664_a.jpg
[id] => 194601237
[full_name] => Jose Antonio Lopez Sosa
)
)
【问题讨论】:
标签: arrays symfony multidimensional-array twig