2016-07-15 75 views
2

我正在建立我的第二个Jekyll网站,我试图使页面布局拉不同包括基于变量。动态包括在液体Jekyll

例如,在download.md

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

这样,网站将不再编译。它说

液体错误(第17行):错误的参数数量(4为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> 

回答

2

你不看在正确的地方。 “第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,您可以将limit: nwhere过滤器移动到for循环。

+0

修复了它!谢谢! – Erica

0

变化:

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

要:

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

它给了我同样的错误。 – Erica

+0

我可以看到你的代码吗?它在github上吗?除了缺少的内容外,我获得了成功的构建。你的jekyll服务/终端说什么? – JoostS

+0

https://github.com/energy7/datastore/ - 但我没有推到gh-pages分支,因为它被破坏 – Erica