22 Apr 2019

Jekyll Liquid Tag: Ignore Whitespace

Jekyll uses the Liquid language to define application logic in your templates. You may write something like the following code snippet to only display some code on one page.

{% if page.name == "Hello World" %}
<p>Hello World</p>
{% endif %}

This code is problematic in that it generates unnecessary whitespace in your resulting webpage. You can modify the code with a - character to make Jekyll ignore it’s whitespace.

The code would look something like this:

{%- if page.name == "Hello World" -%}
<p>Hello World</p>
{%- endif -%}

With the result looking like this: