Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I chain/connect liquid tags as a one-liner? Is there a separator symbol?

Tags:

jekyll

liquid

This is the code which works fine in a jekyll-template:

{% if link.url contains 'http' %}
   {% assign domain = '' %}
{% else %}
   {% assign domain = site.url %}
{% endif %}

Is there a way to make this a one-liner in liquid something like this:

{% if link.url contains 'http' assign domain = '' else assign domain = site.url endif %}

Or do I always have to use {% %} to separate the commands? This looks so ugly.

{% if link.url contains 'http' %}{% assign domain = '' %}{% else %}{% assign domain = site.url %}{% endif %}
like image 863
Phlow Avatar asked Nov 11 '22 03:11

Phlow


1 Answers

If you need the output to render on one line (or fewer), in order to reduce white space, then you can use tags like {%- if something -%}: the additional hyphens remove all leading and trailing space.

like image 99
Rick Davies Avatar answered Nov 28 '22 00:11

Rick Davies