2016-07-15 74 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