我正在构建我的第二个 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>
最佳答案
您没有看对地方。 “第 17 行”是从某种流畅的解析角度来看的,与您的代码行编号无关。
真正的问题是您尝试在 where
过滤器上使用无效的 limit: n
。
limit: 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 %}
..
index.html 中的第 21、25 和 43 行又出现了 3 处,您可以将 limit: n
从 where
过滤到 for
循环。
关于ruby - Dynamic 包含在 Jekyll with Liquid 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38405227/