Dynamic 包含在 Jekyll 和 Liquid 中

Dynamic includes in Jekyll with Liquid

我正在构建我的第二个 Jekyll 站点,我正在尝试根据变量使页面布局引入不同的包含。

例如,在download.md中:

layout: page  
form: "free"  
sidebar: "terms"

有了这个,网站将不再编译。它说

Liquid error (line 17): wrong number of arguments (4 for 3).

第 17 行是下面示例中的第一个 if 语句。

我应该如何设置这些包含?

<article class="s-article t-twocol__article">
  <header class="s-article__header">
    <h1 class="s-article__title">{{ page.title }}</h1>
    <h4 class="s-article__lede">{{ page.lede }}</h4>
  </header>
  <div class="s-article__content">
    {% if {{page.form}} == "full" %}
      {% include c-form--full.html %}
    {% endif %}
    {% if {{page.form}} == "free" %}
      {% include c-form--free.html %}
    {% endif %}
    {{ content }}
  </div>
</article>

变化:

{% if {{page.form}} == "free" %}
{% if {{page.form}} == "full" %}

收件人:

{% if page.form == "free" %}
{% if page.form == "full" %}

你没看对地方。 "Line 17" 是从一些液体解析的角度来看的,与您的代码行编号无关。

真正的问题是您尝试在无效的 where 过滤器上使用 limit: nlimit: n(以及 offset: n)只能用于 for in 循环。

_layout/page.html - 第 47 行

{% assign cards = site.posts | where:"type","premium" limit:1 %}
  {% for card in cards %}
    ..

必须改为:

{% assign cards = site.posts | where:"type","premium" %}
  {% for card in cards limit:1 %}
    ..

并且在第 21、25 和 43 行的 index.html 中又出现了三个,您可以在其中将 limit: nwhere 过滤到 for 循环。