Erica Erica - 1 year ago 85
Ruby Question

Dynamic includes in Jekyll with Liquid

I'm building my second Jekyll site, and trying to make my page layout pull in different includes based on variables. i.e., in, I say

layout: page

form: "free"

sidebar: "terms"

But the site will no longer compile, it says

Liquid error (line 17): wrong number of arguments (4 for 3)
. (Line 17 is the first if statement.) How should I set up these includes? Thanks!

<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>
<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 }}

Answer Source

You're not looking at the right place. "Line 17" is from some liquid parsing point of view and not related to your code line numbering.

The real problem is that you try to use limit: n on the where filter which is not valid. The limit: n (as well as offset: n) can only be used on for in loop.

_layout/page.html - line 47

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

Must be changed to :

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

And you have three more occurrences in index.html at lines 21, 25 and 43, where you can move the limit: n from the where filter to the for loop.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download