jekyll 变量,if 函数

标签 jekyll liquid

为什么这样的东西不起作用? 我尝试过滤今年的所有帖子

<div class="tiles">
{% for post in site.categories.articles %}

  {% capture pubyear %} {{ post.date | date: "%Y" }} {% endcapture %}

    {% if pubyear == "2014" %}
      {% include post-grid.html %}
    {% endif %}

{% endfor %}
</div><!-- /.tiles -->

最佳答案

问题是它正在捕获其中包含一些空格的输出,因此它无法通过 if 条件,删除这些空格并且它应该可以工作

<div class="tiles"> 
  {% for post in site.categories.articles %}
    {% capture pubyear %}{{ post.date | date: "%Y" }}{% endcapture %} 
    {% if pubyear == "2014" %} 
      {% include post-grid.html %} 
    {% endif %}
  {% endfor %}
</div>

关于jekyll 变量,if 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44265571/

相关文章:

ruby - 尝试在 Jekyll 中打印发布日期失败,方法未定义 `strftime'

ruby - Jekyll 忽略帖子中的 Liquid 标签

ruby - 如何在 Jekyll 中没有 html 扩展名的情况下使用 page.url 链接到页面?

.net - 创建一个实现 ILiquidizable 的 DataRow 类

Jekyll 在 HTML 中使用 config.yml 值

ruby - 安装 Jekyll 时出错,需要 Ruby >= 2.0.0

jekyll - 使用 Jekyll 和 Liquid 进行排序的导航菜单

type-conversion - 在 Shopify Liquid 中将字符串转换为整数?

ruby - Jekyll 'include' 配置选项现在必须指定为数组

count - 杰基尔+液体: number of posts by month