Skip to main content
Settings
Color Mode
Theme Skin
Background

Appearance preferences are saved in this browser only.

Environment
Current Environment Production

Built with JEKYLL_ENV=production. Changes require deployment.

Quick Links
Theme & Build
Jekyll v3.10.0
Last Build Aug 14, 02:57
Page Location
Page Info
Layout default
Collection docs
Path _docs/jekyll/jekyll-liquid.md
URL /docs/jekyll-liquid/
Date 2016-01-19

Jekyll - Liquid

Table of Contents

Useful tricks of Liquid, which are used in Jekyll.

1. Liquid

Jekyll uses the Liquid templating language to process templates.

Generally in Liquid you output content using two curly braces e.g. {{ variable }} and perform logic statements by surrounding them in a curly brace percentage sign e.g. {% if statement %}. To learn more about Liquid, check out the official Liquid Documentation.

1. Comment

Allows you to leave un-rendered code inside a Liquid template. Any text within the opening and closing comment blocks will not be output, and any Liquid code within will not be executed.
Input:

Anything you put between {% comment %} and {% endcomment %} tags
is turned into a comment.

Output:

Anything you put between  tags
is turned into a comment.

2. Raw

Raw temporarily disables tag processing. This is useful for generating content (eg, Mustache, Handlebars) which uses conflicting syntax.
Input:

{% raw %}
In Handlebars,  {{ this }} will be HTML-escaped, but {{{ that }}} will not. {% endraw %}

Output:

  In Handlebars,  {{ this }} will be HTML-escaped, but {{{ that }}} will not.

3. forloop.first

Returns true if it’s the first iteration of the for loop. Returns false if it is not the first iteration.

{% for product in collections.frontpage.products %}
    {% if forloop.first == true %}
        First time through!
    {% else %}
        Not the first time.
    {% endif %}
{% endfor %}

4. Blank Line

Input:

{% assign my_variable = "tomato" %}
{{ my_variable }}

Output:


tomato

Notice, one blank line above the desired output.

Add dash - to the input:

{%- assign my_variable = "tomato" -%}
{{ my_variable }}

Output:

tomato

5. Iteration

for

{% for product in collection.products %}
  {{ product.title }}
{% endfor %}

limit
Limits the loop to the specified number of iterations.
Input:

<!-- if array = [1,2,3,4,5,6] -->
{% for item in array limit:2 %}
  {{ item }}
{% endfor %}

Output:

1 2

6. References