A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://shopify.github.io/liquid/basics/whitespace/ below:

Whitespace control – Liquid template language

Whitespace control

In Liquid, you can include a hyphen in your tag syntax {{-, -}}, {%-, and -%} to strip whitespace from the left or right side of a rendered tag.

Normally, even if it doesn’t print text, any line of Liquid in your template will still print a blank line in your rendered HTML:

Input

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

Notice the blank line before “tomato” in the rendered template:

Output

By including a hyphen in your assign closing delimiter, you can strip the whitespace following it from the rendered template:

Input

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

Output

If you don’t want any of your tags to print whitespace, as a general rule you can add hyphens to both sides of all your tags ({%- and -%}):

Input

{% assign username = "John G. Chalmers-Smith" %}
{% if username and username.size > 10 %}
  Wow, {{ username }} , you have a long name!
{% else %}
  Hello there!
{% endif %}

Output without whitespace control



  Wow, John G. Chalmers-Smith , you have a long name!

Input

{% assign username = "John G. Chalmers-Smith" -%}
{%- if username and username.size > 10 -%}
  Wow, {{ username -}} , you have a long name!
{%- else -%}
  Hello there!
{%- endif %}

Output with whitespace control

Wow, John G. Chalmers-Smith, you have a long name!

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4