3

我不喜欢使用 Liquid 和 Jekyll。我正在使用它们来管理我为 Github Pages 创建的响应式引导模板的内容。在我的主页上,我返回了我最近六篇文章的截断摘要,每栏三篇文章。

{% if content == nil %}
{% assign content = post.content %}
{% endif %}
          <h5>{{ post.title }}</h5>
          <p>{{ post.content | strip_html | truncatewords: 38 }} <a href="{{ site.url }}{{ post.url }}">Read more &raquo;</a></p>

我一直未能找到在第三个结果之后插入“</div><div>”的方法。我试过循环和循环但没有运气。

社区可以提供此菜鸟的任何帮助将不胜感激。完成后,我将在 Github 上开源此模板。

4

3 回答 3

1

cycle should work:

{% cycle '', '', '', '</div><div>' %}
于 2012-12-30T12:26:03.957 回答
0

如果您使用 for 循环遍历 post.content,则可以使用 forloop.index 或 forloop.index0 来确定当前迭代是否可以被三除并插入</div><div>.

查看http://wiki.shopify.com/UsingLiquid#For_loops

于 2012-11-30T07:32:39.047 回答
0

这应该有效(它适用于第一个,所以为什么不是第三个!)

{% if forloop.third %}
<aside class="ad">
    <p>sponsored by...</p>
    <!-- ad stuff -->
</aside>
{% endif %} 
于 2013-07-12T21:45:13.963 回答