【问题标题】:Column Brake on 4th Post第四柱上的柱式制动器
【发布时间】:2012-11-18 08:49:11
【问题描述】:

我不喜欢使用 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>

我一直未能找到在第三个结果之后插入“

”的方法。我试过循环和循环,但没有运气。

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

【问题讨论】:

    标签: jekyll liquid github-pages


    【解决方案1】:

    如果你用for循环遍历post.content,你可以使用forloop.index或者forloop.index0来判断当前迭代是否可以被三除,然后插入&lt;/div&gt;&lt;div&gt;

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

    【讨论】:

      【解决方案2】:

      cycle 应该可以工作:

      {% cycle '', '', '', '</div><div>' %}
      

      【讨论】:

        【解决方案3】:

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

        {% if forloop.third %}
        <aside class="ad">
            <p>sponsored by...</p>
            <!-- ad stuff -->
        </aside>
        {% endif %} 
        

        【讨论】:

          猜你喜欢
          • 2016-07-07
          • 1970-01-01
          • 2013-09-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-04-16
          • 1970-01-01
          相关资源
          最近更新 更多