【问题标题】:jekyll: check if there are no postsjekyll:检查是否没有帖子
【发布时间】:2017-09-14 00:11:40
【问题描述】:

如何查看_posts 文件夹中是否没有帖子?

到目前为止,我已经尝试过

{% if site.posts == null %}
  <p>No posts...yet.</p>
{% endif %}

{% if site.posts == nil %}
  <p>No posts...yet.</p>
{% endif %}

在 Liquid 中这可能吗?

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    获取帖子数组的大小,然后将其与 0 进行比较:

    {% assign psize = site.posts | size %}
    {% if psize == 0 %} 
      <p>No posts...yet.</p>
    {% endif %}
    

    【讨论】:

    • 这也不起作用(即这不显示&lt;p&gt;元素)。
    【解决方案2】:

    这是一个更简单的方法。

    {% if site.posts.size == 0 %}
      <p>No posts...yet.</p>
    {% endif %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多