How can I display results in bootstrap grid in octobercms?

孤街醉人 提交于 2019-12-08 11:03:07

问题


I have this right now in my octobercms code to display results. It currently displays it in a list but I want it in bootstrap grid of 3 equal columns.

{% 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 %}

Any straight forward way of doing this?


回答1:


Got it done using this

{% 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 %}



回答2:


To be able to do this dynamically you would need to hold track when you need to start and close a new row. This can be done in twig by using something like this,

{% 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 %}

demo



来源:https://stackoverflow.com/questions/55047174/how-can-i-display-results-in-bootstrap-grid-in-octobercms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!