我现在已经在我的八进制代码中显示结果了。它目前显示在一个列表中,但我希望它在由3列组成的引导网格中。
{% for cats in cats %}
<div>
<img src="{{ cats.poster.path }}"><br>
<a href="{{ 'subcategory'|page({ slug: cats.slug }) }}">
{{ cats.cat_title }}
</a>
</div>
{% else %}
<div class="no-data">{{ noRecordsMessage }}</div>
{% endfor %}有直接的方法吗?
发布于 2019-03-07 20:28:48
用这个做完
{% for row in cats|batch(3) %}
<div class="row">
{% for cats in row %}
<div class="col-sm-4">
<img src="{{ cats.poster.path }}"><br>
<a href="{{ 'subcategory'|page({ slug: cats.slug }) }}">{{ cats.cat_title }}</a>
</div>
{% endfor %}
</div>
{% else %}
<div class="no-data">{{ noRecordsMessage }}</div>
{% endfor %}发布于 2019-03-07 15:43:40
为了能够动态地完成这个任务,您需要在需要启动和关闭新行时保持跟踪。这可以在twig中通过使用这样的方法来实现,
{% for i in 1 .. 10 %}
{% if loop.index0 is divisible by(3) %}
<div class="row">
{% endif %}
<div class=".col-md-4">{{ i }}</div>
{% if loop.index is divisible by(3) or loop.last %}
</div>
{% endif %}
{% endfor %}https://stackoverflow.com/questions/55047174
复制相似问题