【问题标题】:Pass include parameter to select folder from collections in Jekyll传递包含参数以从 Jekyll 的集合中选择文件夹
【发布时间】:2016-09-21 01:41:19
【问题描述】:

我正在建立一个关于 Jekyll 3.0.3 的学术期刊,其中包含期刊问题。现在我正在尝试构建一个所有问题都可以共享的自动构建的目录,使用包含来添加它,并通过 YAML 标头中的“订单”值中的值对页面进行排序。我正在使用集合来分离问题。例如,第一个问题位于名为_issue01 的文件夹中。

_issue02 等中的第二个问题。我正在尝试使用以下语法从包含它的地方传入一个参数:

{% include toc.html foo=site.issue01 %}

然后在toc.html 上接收foo 使用:

{% assign documents = {{include.foo}} | sort: 'order' %}

过滤器在抱怨:

错误:Liquid 错误(第 13 行):无法对空对象进行排序。

我尝试了另一种方法,从 thread 中汲取灵感。

{% capture foo %}{{ site.issue01 }}{% endcapture %}
{% include foo.html %}

但这似乎将整个事情作为一个字符串传递:

错误:# 的未定义方法“排序”

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    我找到了答案:

    在要包含目录的文件中:

    {% include toc.html bar=site.issue01 %}
    

    toc.html 中,诀窍是使用括号:

    {% assign documents = (include.bar | sort: 'order') %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      • 2019-07-08
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多