#liquid#url

Creates an absolute path url. The path will include the value of the "url" and "baseurl" settings from the _config.yml file.

{{ "/assets/app.js" | absolute_url }}
// Returns https://shortcode.dev/assets/app.js
copy
#liquid#array

You cannot create an array directly in Liquid, however you can go around it by splitting a string.

 {%  assign listOfItems = "cup,pen,apple,book" | split: ',' %}
copy
#liquid#variable

Assign data to a variable.

 {% assign myVar = 'Say hello' %}

 {{ myVar }}
copy
#liquid#string#filter

Capitalize string.

 {{ "capitalize this sentence." | capitalize }}

Output:
Capitalize this sentence.
copy
#liquid#variable

Capture is a very handy Liquid function for assigning structured data to a variable.

 {% capture myVar  %}
     {% for item in array  %}
        {{ item.title  }}
     {% endfor  %}
 {% endcapture  %}

 {{ myVar  }}
copy
#liquid
 {% comment  %} Body of your comment  {% endcomment  %}
copy
#liquid#date

Get current time and date.

 {{ site.time  }}

Output:
2020-11-12 22:57:58 +0000
copy
#liquid#date#filter

Format date to long strings.

 {{ site.time | date_to_long_string  }}

Output:
12 November 2020
copy
#liquid#date#filter

Format date to rfc822.

 {{ site.time | date_to_rfc822  }}

Output:
Thu, 12 Nov 2020 22:57:58 +0000
copy
#liquid#date#filter

Format date to strings.

 {{ site.time | date_to_string  }}

Output:
12 Nov 2020
copy
#liquid#date#filter

Format date to xml schema.

 {{ site.time | date_to_xmlschema  }}

Output:
2020-11-12T22:57:58+00:00
copy
#liquid#navigation#collections#snippet

Simple loop getting name, permalink and a number of posts for each collection type.

<ul>
 {% for item in site.collections  %}
  <li>
      <a href="/ {{ item.permalink  }}" title="{{ item.label }}">
        {{ item.label }} ({{ site[item.label] | size }})
      </a>
  </li>
 {% endfor  %}
</ul>
copy
#liquid

You can escape liquid tags from being processed by using this pattern.

 {{"  {%  include file.html  "}} %}
 {% comment  %} It returns  {% include file.html  %} without parsing.  {% endcomment  %}
copy
#liquid#for#loop

Example of a simple Liquid for loop returning a list of pages.

<ul>
{% for page in site.pages %}
  <li>
      <a title="{{ page.title }}" href="{{ page.url }}">{{ page.title }} </a>
  </li>
{% endfor %}
</ul>
copy
#liquid#posts

Get a collection of all posts and display the title and the url in a list format.

<ul>
    {% for post in site.posts %}
    <li>
        <a href="{{ post.url }}">{{ post.title }}</a>
    </li>
    {% endfor %}
</ul>
copy
#liquid#tags

A simple script to get all tags from the front matter of a post/page.

{% if page.tags.size > 0 %}
    {% for tag in page.tags %}<span>#{{ tag }}</span>{% endfor %}
{% endif %}
copy
#liquid#conditional

Conditional if statement.

{% if page.title %}
  <h1>{{ page.title }}</h1>
{% endif %}
copy
#liquid

Include files from the "_include" directory. You can also pass parameters to the include tags.

 {% include page_header.html title=page.title  %}
copy
#liquid#filter

Converts a variable to a string. Useful while debugging.

 {{  page.tags | inspect }}

Output:
[&quot;liquid&quot;, &quot;filter&quot;]
copy
#liquid#filter

Convert data to json format.

{{ page.tags | jsonify }}
Outputs:
["liquid","filter"]
copy
#liquid#for#loop

You can use limit attribute to restrict the numbers of returned results by the for loop.

<ul>
{% for page in site.pages limit:5 %}
  <li>
      <a title="{{ page.title }}" href="{{ page.url }}">{{ page.title }} </a>
  </li>
{% endfor %}
</ul>
copy
#liquid#filter

Converts markdown to HTML code.

{{ page.title | markdownify }}
copy
#liquid#filter

Counts the number of words in the text.

{{  "How many words is in this phrase?" | number_of_words }}
7
copy
#liquid#posts

Returns the .

{% for post in site.posts %}
<p>
    {{ post.excerpt }}
</p>
{% endfor %}
copy
#liquid#url

Creates a relative path url. The path will include the value of the "baseurl" setting from the _config.yml file if set.

 {{  "/assets/app.js" | relative_url }}
copy
#liquid#filter

Filters out first quoted characters.

 {{ ", one, two, three, four" | remove_first: ", " }}

Output:
one, two, three, four
copy
#liquid#filter

Convert sass to css code. Use "scssify" flag to convert scss.

{{ page.sass | sassify }}
copy
#liquid#string#array#filter

Count the number of characters in a string or length of an array. "." or "|" syntax can be used.

 {{ arrayOfItems.size  }}
 {% comment  %} or  {% endcomment  %}
// or
 {{  "How many characters?" | size }}
 {% comment  %} This will return 20  {% endcomment  %}
copy
#liquid#filter

Convert some text to a URL safe string. Use the following flags for different results - "pretty", "ascii", "latin".

{{ "It works 100%, even with an 'ó' character!" | slugify }}
it-works-100-even-with-an-ó-character

{{ "It works 100%, even with an 'ó' character!" | slugify: "pretty" }}
it-works-100-,-even-with-an-'ó'-character!

{{ "It works 100%, even with an 'ó' character!" | slugify: "ascii" }}
it-works-100-even-with-an-character

{{ "It works 100%, even with an 'ó' character!" | slugify: "latin" }}
it-works-100-even-with-an-o-character
copy
#liquid#filter

Convert string to an integer.

{{ "22" | to_integer }}
22
copy
#liquid#string#filter

Trim string to the number of characters specified. By default the truncated string will end with ellipsis (...) however you can replace it by passing your ending as the second parameter.

{{  "Some string to be truncated" | truncate:9 }}
    String...
{{  "Some string to be truncated" | truncate:9, "...trimmed" }}
    String...trimmed
copy
#liquid#conditional

Ignore if the condition is met.

 {% unless page.title == 'home'  %}
  Not a homepage
 {% endunless  %}
copy
#liquid#string#filter

Transform all string to uppercase.

 {{ "make uppercase" | upcase }}

Output:
MAKE UPPERCASE
copy
#liquid#xml#filter

Escape special characters to use in xml.

{{ page.content | xml_escape }}
copy
Sitemap Git repository