Liquid Tags and Filters

Jekyll extends liquid with a few additional template tags and filters, Glim implements the following:

Filters: slugify, markdownify, xml_escape, cgi_escape, absolute_url, relative_url, date_to_xmlschema, date_to_rfc822, date_to_string, date_to_long_string, group_by, group_by_exp, where.

Tags: link, post_url, include, highlight.

Note that liquid actually has its own include tag but with syntax that is incompatible with Jekyll. Glim does not override the default include tag but instead preprocess the templates to convert Jekyll’s syntax so that it is compatible with liquid, but expressions are currently not supported.

The link tag has been superseded by a path_to_url filter. The advantage of a filter is that it can be chained, for example with relative_url or absolute_url, but also that it allows variables as input. For example if we are storing our site’s menu structure in a data file (e.g. site.data.menu) then there is no way to use path references with the link tag, and we would have to hardcode URLs in the data structure, which means we would not get an error if we reference a non-existing resource. By using a filter, we can store file paths in the data structure and filter them through path_to_url, even do something like this:

{%- for item in site.data.menu %}
  {%- assign url = item.path | path_to_url | default: item.url %}
  <li><a href="{{ url }}">{{ item.title }}</a></li>
{%- endfor %}

When using the link tag or path_to_url then one can leave out the extension or in the case of index files, the entire filename. For example {% link blog/ %} can be used instead of {% link blog/index.md %}.