For loop 杰基尔:For循环中的备用类
我想知道是否有一种方法可以在for循环中的类之间切换 目前,我正在重复我的For loop 杰基尔:For循环中的备用类,for-loop,jekyll,cycle,For Loop,Jekyll,Cycle,我想知道是否有一种方法可以在for循环中的类之间切换 目前,我正在重复我的块,并添加一个.clearfix 第二个后的div {% for post in site.posts %} {% capture thecycle %}{% cycle 'odd', 'even' %}{% endcapture %} {% if thecycle == 'odd' %} <article class="md-col-5"> ... </article
块,并添加一个.clearfix
第二个
后的div
{% for post in site.posts %}
{% capture thecycle %}{% cycle 'odd', 'even' %}{% endcapture %}
{% if thecycle == 'odd' %}
<article class="md-col-5">
...
</article>
{% else %}
<article class="md-col-5 md-col-offset-2">
...
</article>
<div class="clearfix"></div>
{% endif %}
{% endfor %}
这对杰基尔有可能吗
感谢您的帮助。提前谢谢 您不需要实际检查
偶数
或奇数
,如果需要,您可以使用循环
-helper实际分配额外的类。此外,您可以检查该字符串,并仅在需要时添加clearfix:
{% for post in site.posts %}
{% capture thecycle %}{% cycle 'md-col-offset-2', '' %}{% endcapture %}
<article class="md-col-5 {{ thecycle }}">
...
</article>
{% if thecycle == 'md-col-offset-2' %}
<div class="clearfix"></div>
{% endif %}
{% endfor %}
{%for site.posts%}
{%capture thecycle%}{%cycle'md-col-offset-2',''%}{%endcapture%}
...
{%if thecycle=='md-col-offset-2%}
{%endif%}
{%endfor%}
这是一个很好的解决方案。总共有4篇文章,有没有办法不让第二篇.clearfix
在第四篇文章之后出现?当然。您可以使用{%if thecycle=='md-col-offset-2'和forloop.last==false%}
跳过clearfix,如果它是最后一次迭代。逻辑很棒。谢谢你这么好的解决方案!
{% for post in site.posts %}
{% capture thecycle %}{% cycle 'md-col-offset-2', '' %}{% endcapture %}
<article class="md-col-5 {{ thecycle }}">
...
</article>
{% if thecycle == 'md-col-offset-2' %}
<div class="clearfix"></div>
{% endif %}
{% endfor %}