打印出数组中的key,value
{% for index, item in content%}
{{ index }}
{{ dump(item['attributes']['slug']) }}
{{ dump(item['attributes']['title']) }}
{{ dump(item['id']) }}
{% endfor %}
for操作,不管是否有内容,每列显示三行
{% for i in 0..2 %}
{% if content[i] %}
{% set item = content[i] %}
<li>
<a href="{{ site }}/d/{{ item['id'] }}-{{ item['attributes']['slug'] }}">{{ item['attributes']['title'] }}</a>
<br>
<div class="date">
{{ item['attributes']['createdAt']|slice(0, 10) }}
</div>
</li>
{% else %}
<li></li>
{% endif %}
{% endfor %}
网友评论