文章

Liquid Templates in Practice: How This Jekyll Site Renders Itself

A hands-on tour of the Liquid template language using this repository as the source material: how Jekyll turns front matter plus content into pages, how the Chirpy theme uses Liquid, and where you can safely customize it.

Liquid Templates in Practice: How This Jekyll Site Renders Itself

This site is a Jekyll 4.4.1 site running the Chirpy 7.5.0 theme. Every page you see is produced by Liquid — Jekyll’s template language. The repository itself has no local _layouts/ or _includes/ directory: all of the HTML you see comes from the theme gem at

1
$(bundle show jekyll-theme-chirpy)   # → .../gems/jekyll-theme-chirpy-7.5.0

which means that understanding Liquid is the difference between “I can write posts” and “I can change how this site actually looks”.

The versions in play (from Gemfile.lock) are:

ComponentVersion
Jekyll4.4.1
Liquid4.0.4
jekyll-theme-chirpy7.5.0
kramdown2.5.2

The rendering pipeline

Jekyll does roughly this for every page:

  1. Read the file’s YAML front matter (--- block) into variables.
  2. Read the rest as content.
  3. Run the content through Liquid (this is where {{ }} and {% %} are evaluated).
  4. Run the result through kramdown (Markdown → HTML).
  5. Wrap it in the layout chain, each layout itself also rendered by Liquid.

The third step is the one people forget: Liquid runs before Markdown. That is why a post can contain a tag like the one this repo uses for internal links:

1
[六边形架构实践]({% post_url 2026-05-31-gitlab-hexagonal-architecture %})

and why the {% raw %} tag is essential when you want to show Liquid code in a post (see Escaping Liquid in posts).

Which objects are available

At render time Liquid receives a fixed set of objects:

ObjectWhat it isExample from this repo
siteGlobal site data from _config.yml + _data/*site.title, site.data.locales
pageThe document being rendered (post, page, tab)page.title, page.tags, page.pin
layoutThe current layout’s front matterlayout.panel_includes in default.html
contentThe already-rendered inner content{{ content }} in post.html
paginatorPagination info (only on paginated pages)paginator.per_page, paginator.total_pages
jekyllBuild metadatajekyll.environment, jekyll.version
themeName of the themesite.theme used in head.html
includeParameters passed to the includeinclude.lang, include.date

In _layouts/default.html you can see layout, content and jekyll used together:

1
2
3
4
5
{% if layout.layout == 'default' %}
  {% include refactor-content.html content=content lang=lang %}
{% else %}
  {{ content }}
{% endif %}

and later, layout.script_includes is looped over to inject the right <script> tags per layout.

Syntax basics

Liquid has exactly two kinds of markup.

Output — prints a value:

1
2
{{ site.title }}
{{ post.date | date: '%Y' }}

Tags — control flow and logic, prints nothing by themselves:

1
2
3
4
{% assign title = page.title %}
{% if page.description %}
  <p>{{ page.description }}</p>
{% endif %}

Whitespace control

Adding - inside a delimiter strips the surrounding whitespace. This matters a lot in XML/JSON templates. assets/feed.xml is wrapped in a capture so it can post-process the whole feed:

1
2
3
4
5
6
{% capture source %}
<feed xmlns="http://www.w3.org/2005/Atom">
  ...
</feed>
{% endcapture %}
{{ source | replace: '&', '&amp;' }}

and _includes/read-time.html uses {%- ... -%} to avoid injecting stray spaces into a tooltip title:

1
2
3
{%- capture read_prompt -%}
  {{- site.data.locales[include.lang].post.read_time.prompt -}}
{%- endcapture -%}

Truthiness

Liquid treats only nil and false as falsy. An empty string, empty array and 0 are truthy. Use empty or size explicitly. _includes/sidebar.html guards against an unset avatar with both:

1
2
3
{%- if site.avatar != empty and site.avatar -%}
  ...
{%- endif -%}

Comments and raw

{% comment %} removes a block from the output (the theme uses it as documentation inside small includes). {% raw %} disables Liquid for its content — see Escaping Liquid in posts.

Front matter becomes page

The whole point of front matter is to feed Liquid. This site sets defaults in _config.yml so that posts do not need to repeat their layout:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
defaults:
  - scope:
      path: ""
      type: posts
    values:
      layout: post
      comments: true
      toc: true
      permalink: /posts/:title/
  - scope:
      path: ""
      type: tabs
    values:
      layout: page
      permalink: /:title/

So a post only needs:

1
2
3
4
5
6
7
8
---
title: "Liquid Templates in Practice"
date: 2026-10-20 09:00:00 -0500
categories: [Web, Jekyll]
tags: [liquid, jekyll, chirpy]
description: >-
  A hands-on tour of Liquid using this repository.
---

Those keys become page.title, page.categories, page.tags, page.description inside the templates. The _tabs/ collection is configured similarly: collections.tabs with sort_by: order means site.tabs is already sorted by the order key that each tab file declares (_tabs/archives.md has order: 3, _tabs/about.md has order: 4, and so on).

Variables, assign and capture

{% assign %} creates a named variable. {% capture %} builds a string from a block — handy when you need to pipe a whole fragment through a filter.

_layouts/post.html uses capture to build HTML attributes, then reuses them:

1
2
3
4
5
6
7
{% if page.image %}
  {% capture src %}src="{{ page.image.path | default: page.image }}"{% endcapture %}
  {% capture class %}class="preview-img{% if page.image.no_bg %}{{ ' no-bg' }}{% endif %}"{% endcapture %}
  {% capture alt %}alt="{{ page.image.alt | xml_escape | default: "Preview Image" }}"{% endcapture %}

  <img {{ src }} {{ class }} {{ alt }} w="1200" h="630">
{% endif %}

Note three things happening at once: default supplies a fallback when the value is missing, xml_escape makes it safe for an attribute, and {% if %} is allowed inside capture.

Important scoping quirk: assign is not block-scoped. A variable assigned inside a for loop stays visible after the loop. _layouts/archives.html relies on exactly that to remember the previous year:

1
2
3
4
5
6
7
8
9
10
11
{% for post in site.posts %}
  {% assign cur_year = post.date | date: '%Y' %}

  {% if cur_year != last_year %}
    {% unless forloop.first %}</ul>{% endunless %}
    <time class="year lead d-block">{{ cur_year }}</time>
    {{ '<ul class="list-unstyled">' }}
    {% assign last_year = cur_year %}
  {% endif %}
  ...
{% endfor %}

last_year survives from iteration to iteration. (Also note {{ '<ul ...>' }} — you can output a literal string to dodge HTML parsing problems.)

Data files: site.data

Everything in _data/ is auto-loaded. This repo has authors.yml, contact.yml, share.yml, legacy_wiki.yml and deleted_posts.yml; the theme adds locales/ and origin/.

_data/authors.yml is tiny:

1
2
3
sky:
  name: Sky Zhao
  url: https://github.com/AriseshineSky

and _layouts/post.html looks it up by key, with a graceful fallback to the site owner:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{% if page.author %}
  {% assign authors = page.author %}
{% elsif page.authors %}
  {% assign authors = page.authors %}
{% endif %}

{% for author in authors %}
  {% if site.data.authors[author].url -%}
    <a href="{{ site.data.authors[author].url }}">{{ site.data.authors[author].name }}</a>
  {%- else -%}
    {{ site.data.authors[author].name }}
  {%- endif %}
  {% unless forloop.last %}{{ '</em>, <em>' }}{% endunless %}
{% endfor %}

The locales data is what makes the UI bilingual without touching templates. Because _config.yml sets lang: zh-CN, {% include lang.html %} resolves lang and every label becomes site.data.locales[lang].post.posted, ...tabs.archives, and so on:

1
2
3
4
5
6
7
8
# _data/locales/zh-CN.yml (shipped by the theme)
tabs:
  home: 首页
  archives: 归档
post:
  posted: 发表于
  read_time:
    unit: 分钟

_includes/sidebar.html even uses the bracket-dot hybrid syntax to look up a tab label by its URL:

1
2
3
4
{% for tab in site.tabs %}
  {% capture tab_name %}{{ tab.url | split: '/' }}{% endcapture %}
  <span>{{ site.data.locales[include.lang].tabs.[tab_name] | default: tab.title | upcase }}</span>
{% endfor %}

Control flow

if / elsif / unless

_includes/toc-status.html is a compact example of derived state:

1
2
3
4
5
6
{% assign enable_toc = false %}
{% if site.toc and page.toc %}
  {% if page.content contains '<h2' or page.content contains '<h3' %}
    {% assign enable_toc = true %}
  {% endif %}
{% endif %}

post.html then reuses enable_toc (set by the include) to decide whether to emit the TOC UI. contains is a string/array operator; and / or / != combine conditions.

case / when

Branches on equality, with comma-separated alternatives. _includes/language-alias.html maps Rouge lexer aliases to display names — the else branch is the fallback:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{% assign _lang = include.language | default: '' %}

{% case _lang %}
  {% when 'py' %}
    {{ 'Python' }}
  {% when 'rb' %}
    {{ 'Ruby' }}
  {% when 'bash', 'zsh', 'ksh', 'sh' %}
    {{ 'Shell' }}
  {% when 'css', 'html', 'scss', 'toml', 'xml', 'yaml', 'json' %}
    {{ _lang | upcase }}
  {% else %}
    {{ _lang | capitalize }}
{% endcase %}

for and forloop

for iterates arrays, hashes and ranges. Inside the loop, forloop exposes first, last, index (1-based), index0 (0-based), length and rindex.

Arrays are sorted with sort / sort_natural (case-insensitive), reversed with reverse, limited and offset inline. This site’s tag cloud builds its own ranking because Liquid 4 has no sum:

1
2
3
4
5
6
7
8
9
10
11
12
13
{% assign MAX = 10 %}
{% assign size_list = '' | split: '' %}
{% assign tag_list = '' | split: '' %}

{% for tag in site.tags %}
  {% assign size = tag | last | size %}
  {% assign size_list = size_list | push: size %}
  {% assign tag_str = tag | first | append: '::' | append: size %}
  {% assign tag_list = tag_list | push: tag_str %}
{% endfor %}

{% assign size_list = size_list | sort | reverse %}
{% assign tag_list = tag_list | sort_natural %}

A hash iterated with {% for x in hash %} yields [key, value] pairs, which is why you see tag | first and tag | last. '' | split: '' is the idiomatic way to create an empty array, and push appends to it (a Jekyll filter, not a Liquid one). {% break %} and {% continue %} work as you would expect; _includes/trending-tags.html breaks out of the inner loop once a tag is found.

Ranges are common for index arithmetic. home.html combines paginator math, ranges and push to merge pinned posts with normal posts:

1
2
3
4
5
6
7
8
9
10
{% assign all_pinned = site.posts | where: 'pin', 'true' %}
{% assign all_normal = site.posts | where_exp: 'item', 'item.pin != true and item.hidden != true' %}

{% assign visible_start = paginator.page | minus: 1 | times: paginator.per_page %}
{% assign visible_end = visible_start | plus: paginator.per_page %}

{% assign posts = '' | split: '' %}
{% for i in (visible_start..all_pinned.size) limit: pinned_size %}
  {% assign posts = posts | push: all_pinned[i] %}
{% endfor %}

Filters

Filters transform values with |. They can take arguments and chain freely. Jekyll ships Liquid 4.0.4 plus its own filter module, so the available set is “Liquid standard filters + Jekyll filters”.

URL and path filters

The two you will use most are relative_url and absolute_url — never hard-code a path:

1
2
3
<a href="{{ '/' | relative_url }}">{{ site.title }}</a>
<a href="{{ post.url | relative_url }}">{{ post.title }}</a>
<img src="{{ '/assets/img/avatar.png' | relative_url }}">

_includes/media-url.html is a mini-framework on top of them: it prepends site.cdn and page.media_subpath, normalizes duplicate slashes, and only then decides whether to make the URL absolute.

String filters in the wild

_includes/post-summary.html turns a rendered post into a one-line teaser by chaining six filters:

1
2
3
4
5
6
7
8
9
{%- assign content = content
  | markdownify
  | strip_html
  | newline_to_br
  | replace: '<br />', ' '
  | strip_newlines
  | strip
-%}
{%- assign content = content | truncate: max_length -%}

_layouts/post.html builds category and tag URLs with slugify + url_encode, which is what makes Chinese tags produce valid, stable URLs:

1
2
3
4
{% for category in page.categories %}
  <a href="{{ site.baseurl }}/categories/{{ category | slugify | url_encode }}/">{{ category }}</a>
  {%- unless forloop.last -%},{%- endunless -%}
{% endfor %}

Other everyday filters: append, prepend, remove, replace, split, join, downcase, upcase, capitalize, slice, first, last, size, default, truncate.

Date filters

date formats with strftime, and the theme deliberately stores the format per locale so that translations can reorder day and month. _includes/datetime.html emits a <time> element carrying both a Unix timestamp and a day.js format for client-side localization:

1
2
3
4
5
6
7
8
9
{% assign df_strftime = site.data.locales[include.lang].df.post.strftime | default: '%d/%m/%Y' %}
{% assign df_dayjs = site.data.locales[include.lang].df.post.dayjs | default: 'DD/MM/YYYY' %}

<time
  data-ts="{{ include.date | date: '%s' }}"
  data-df="{{ df_dayjs }}"
>
  {{ include.date | date: df_strftime }}
</time>

feed.xml uses date_to_xmlschema (a Jekyll filter) so the Atom feed is valid:

1
2
<updated>{{ site.time | date_to_xmlschema }}</updated>
<published>{{ post.date | date_to_xmlschema }}</published>

Number filters

plus, minus, times, divided_by, modulo, round, ceil, floor, abs, at_least, at_most, plus Jekyll’s to_integer. _includes/read-time.html computes reading time:

1
2
3
4
5
6
7
{% assign words = include.content | strip_html | number_of_words: 'auto' %}
{% assign wpm = 180 %}
{% assign read_time = words | divided_by: wpm %}

{% unless read_time > 0 %}
  {% assign read_time = 1 %}
{% endunless %}

number_of_words: 'auto' is Jekyll’s extension: it handles CJK text, which is exactly why this Chinese site shows a sensible reading time.

HTML / JSON filters

markdownify, strip_html, xml_escape, jsonify. The site search index is not a static file — it is assets/js/data/search.json rendered by Liquid into JSON:

1
2
3
4
5
6
7
8
9
10
11
12
13
[
  {% for post in site.posts %}
  {
    "title": {{ post.title | jsonify }},
    "url": {{ post.url | relative_url | jsonify }},
    "categories": {{ post.categories | join: ', ' | jsonify }},
    "tags": {{ post.tags | join: ', ' | jsonify }},
    "date": {{ post.date | jsonify }},
    {% capture content -%}{% include post-summary.html full_text=true %}{%- endcapture -%}
    "content": {{ content | jsonify }}
  }{% unless forloop.last %},{% endunless %}
  {% endfor %}
]

Note the comma handling via forloop.last — the classic way to join JSON objects in Liquid. The capture around the include is needed because you cannot pipe the output of a tag directly. _includes/post-sharing.html does the same trick for a JS attribute:

1
customInstanceList="{{ share.instances | jsonify | xml_escape }}"

Includes: the composition mechanism

{% include file.html key=value %} renders another file from _includes/. Parameters arrive as include.key. _includes/datetime.html expects date, lang, optional class and tooltip:

1
{% include datetime.html date=post.date tooltip=true lang=lang %}

Includes are not sandboxed: site, page and content are global, but any assign you do inside an include leaks out (that is how toc-status.html hands enable_toc back to post.html).

Two advanced patterns appear in this codebase.

Dynamic include names. _layouts/default.html turns a layout’s front matter list into includes:

1
2
3
4
{% for _include in layout.panel_includes %}
  {% assign _include_path = _include | append: '.html' %}
  {% include {{ _include_path }} lang=lang %}
{% endfor %}

Computed filenames. _includes/comment.html chooses the provider file from _config.yml, so switching from giscus to utterances is a one-line config change:

1
2
3
4
{% if page.comments and site.comments.provider %}
  {% capture path %}comments/{{ site.comments.provider }}.html{% endcapture %}
  {% include {{ path }} %}
{% endif %}

With comments.provider: giscus in this repo’s _config.yml, that renders _includes/comments/giscus.html, which injects site.comments.giscus.repo, repo_id, category_id and friends into the giscus script.

{% include_cached %} is the performance-conscious variant — it renders once and reuses the HTML for identical arguments. The theme uses it for things that never change per page: favicons.html, footer.html, search-loader.html, trending-tags.html.

Threading arguments is manual. Every level that needs lang must receive it, which is why lang=lang appears on nearly every include call in default.html, post.html and head.html. Forgetting it is the most common cause of a locale label silently falling back to English.

Jekyll-specific tags

TagPurposeExample
{% post_url %}Link to a post by filenameused in this repo’s GitLab posts
{% link %}Link to a file/page by path{% link _tabs/about.md %}
{% highlight %}Highlighted code block{% highlight ruby %}
{% seo %}SEO meta tags (jekyll-seo-tag)_includes/head.html
{% include_relative %}Include relative to the current file—
{% raw %}Disable Liquidsee below

_includes/head.html wraps {% seo %} in a capture so it can rewrite the Open Graph image URL:

1
2
3
4
5
{%- capture seo_tags -%}
  {% seo title=false %}
{%- endcapture -%}
{% assign seo_tags = seo_tags | replace: old_url, new_url %}
{{ seo_tags }}

Escaping Liquid in posts

Because Liquid runs before Markdown on this very file, every delimiter in a post body is executed — including the ones you write inside backticks and fenced code blocks. A code span is not a protection, which is exactly why most of this article is wrapped in one big raw block.

There are two escape techniques.

1. Wrap the snippet in a raw block. Everything between the opening raw tag and its matching closing tag is emitted verbatim and is never evaluated. The catch: a raw block cannot contain its own closing tag, so you cannot demonstrate that closing tag inside the same block.

2. Build the delimiter from a string. An output expression whose value is the two-character sequence that opens a tag is emitted as ordinary text, and Liquid does not re-scan its own output, so the text stays literal. Typing the output expression below, followed by the rest of the tag as plain text, renders a literal tag:

{% if page.image %}…{% endif %}

That is not a live conditional — it was produced by string interpolation, so Liquid never treats it as code. The same works for output expressions: this sentence contains {{ page.title }} without printing any title, and this is a literal closing raw tag: {% endraw %}.

In practice, use technique 1 for whole code blocks and technique 2 for the occasional line that must contain a closing tag. Every fenced Liquid listing in this article, for example, sits inside the outer raw block.

Worked examples from this project

_includes/related-posts.html ranks posts sharing tags and categories. This is the most “programming-like” template in the theme, and a good stress test of Liquid’s capabilities:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{% assign TOTAL_SIZE = 3 %}
{% assign TAG_SCORE = 1 %}
{% assign CATEGORY_SCORE = 0.5 %}
{% assign SEPARATOR = ':' %}
{% assign match_posts = '' | split: '' %}

{% for category in page.categories %}
  {% assign match_posts = match_posts | push: site.categories[category] | uniq %}
{% endfor %}
{% for tag in page.tags %}
  {% assign match_posts = match_posts | push: site.tags[tag] | uniq %}
{% endfor %}

{% assign match_posts = match_posts | reverse %}
{% assign last_index = match_posts.size | minus: 1 %}
{% assign score_list = '' | split: '' %}

{% for i in (0..last_index) %}
  {% assign post = match_posts[i] %}
  {% if post.url == page.url %}{% continue %}{% endif %}

  {% assign score = 0 %}
  {% for tag in post.tags %}
    {% if page.tags contains tag %}{% assign score = score | plus: TAG_SCORE %}{% endif %}
  {% endfor %}
  {% for category in post.categories %}
    {% if page.categories contains category %}{% assign score = score | plus: CATEGORY_SCORE %}{% endif %}
  {% endfor %}

  {% if score > 0 %}
    {% capture score_item %}{{ score }}{{ SEPARATOR }}{{ i }}{% endcapture %}
    {% assign score_list = score_list | push: score_item %}
  {% endif %}
{% endfor %}

{% assign score_list = score_list | sort | reverse %}

The clever part: Liquid cannot sort a list of objects by a computed key, so the template encodes each candidate as "score:index", sorts the strings, then recovers the index with | split: SEPARATOR | last and | to_integer. Two channels in one string. If you ever need to rank things in Liquid, this is the pattern.

The full include chain of a post page

Follow page.permalink for any post and you get this stack:

1
2
3
4
5
6
7
8
9
10
11
12
13
_layouts/post.html
  layout: default
  → _layouts/default.html
      layout: compress
      → _includes/origin-type.html   (sets `type`: cors | basic)
      → _includes/lang.html          (sets `lang`)
      → _includes/head.html          (SEO, CSS, scripts)
      → _includes/sidebar.html       (tabs, contact links)
      → _includes/topbar.html
      → _includes/refactor-content.html  (post-processes rendered HTML)
      → _includes/toc.html / related-posts.html / post-nav.html
      → _includes/comment.html → comments/giscus.html
      → _includes/footer.html

Each arrow is an include. refactor-content.html is worth a look: it uses split, replace and for to post-process already-rendered HTML (wrapping tables, rewriting image tags), proving that Liquid is not limited to producing HTML from data — it can rewrite HTML too.

How the theme interacts with the Ruby plugin

_plugins/posts-lastmod-hook.rb is plain Ruby, not Liquid, but it feeds Liquid by writing a data key:

1
2
3
4
5
6
7
Jekyll::Hooks.register :posts, :post_init do |post|
  commit_num = `git rev-list --count HEAD "#{post.path}"`
  if commit_num.to_i > 1
    lastmod_date = `git log -1 --pretty="%ad" --date=iso "#{post.path}"`
    post.data['last_modified_at'] = lastmod_date
  end
end

post.html then displays it because Liquid can see page.last_modified_at, and update-list.html sorts on it:

1
2
3
4
5
{% assign datetime = post.last_modified_at | default: post.date %}
{% capture elem %}{{ datetime | date: "%Y%m%d%H%M%S" }}::{{ forloop.index0 }}{% endcapture %}
{% assign all_list = all_list | push: elem %}
...
{% assign all_list = all_list | sort | reverse %}

That is the general rule: Ruby plugins compute, Liquid presents.

Customizing the theme from this repo

Because the theme is a gem, you cannot edit its files in place (and you should not — bundle install would discard changes). Jekyll resolves a file in your site directory before the theme directory, so to override any template, create a file with the same relative path:

1
2
3
_includes/read-time.html      → overrides the theme's read-time include
_layouts/post.html            → overrides the whole post layout
_sass/...                     → overrides a stylesheet partial

Practical workflow:

1
2
3
bundle exec jekyll b            # production build into _site/
bash tools/run.sh              # dev server at http://127.0.0.1:4000 with LiveReload
bash tools/test.sh             # build + html-proofer (external links disabled)

Two caveats when overriding:

  • You own the file forever. Theme upgrades will not merge your copy. Keep overrides minimal and copy the upstream version as the starting point.
  • .jekyll-cache/ and _site/ are generated. If a template change does not appear, stop the server, delete .jekyll-cache/, and rebuild. Incremental builds occasionally miss include changes.

Pitfalls checklist

  1. Liquid runs on your Markdown. Any {{ or {% in a post is code. Escape with {{ or {% in a post is code. Escape with {% raw %}.
  2. Malformed Liquid fails the build. A missing {% endif %} breaks the whole site, not just one page. bundle exec jekyll b is the fastest feedback loop.
  3. assign is global to the template. Variables leak out of loops and includes — sometimes useful (see last_year), sometimes a bug source.
  4. Liquid 4 has no sum. Accumulate with {% assign total = total | plus: x %}.
  5. default also replaces false. {% assign x = false | default: 1 %} gives 1. Guard booleans with an explicit if.
  6. Columns and dots differ. site.data.authors[author].url is safe when author is a variable; site.data.authors.author would look for the literal key author.
  7. Whitespace control matters in XML/JSON. Use {%- -%} and {{- -}}, or a capture with strip.
  8. Include arguments do not propagate. Pass lang=lang explicitly down the chain.
  9. Heavy loops over site.posts cost build time. Prefer include_cached for loop-heavy fragments that do not depend on the page.
  10. site.data.legacy_wiki and _data/deleted_posts.yml are consumed by Ruby, not Liquid. Not everything in _data/ needs a template.

Quick reference

Tags

TagNotes
{{ value \| filter }}output, with filters
{% assign x = ... %} / {% capture x %}...{% endcapture %}create a variable / string
{% if %} {% elsif %} {% else %} {% endif %}conditionals
{% unless %} {% endunless %}negated if
{% case %} / {% when %} / {% else %} / {% endcase %}multi-branch equality
{% for x in arr %}...{% endfor %}loop; limit:, offset:, reversed, (1..5)
{% break %} / {% continue %}loop control
{% comment %} / {% endcomment %}removed from output
{% raw %} / {% endraw %}literal Liquid, no evaluation
{% include f.html a=1 %} / {% include_cached %}composition
{% post_url 2026-05-31-gitlab-clean-architecture %}link to a post

Filters by category

CategoryFilters
URL (Jekyll)relative_url, absolute_url, slugify, uri_escape, cgi_escape
String (Liquid)append, prepend, remove, replace, split, truncate, strip, strip_newlines, newline_to_br, downcase, upcase, capitalize, slice, default
HTML/JSON (mixed)escape, xml_escape, strip_html, markdownify, jsonify, smartify, number_of_words
Array (mixed)size, first, last, join, sort, sort_natural, reverse, uniq, map, where, where_exp, find, concat, push (Jekyll), split: '' (empty array)
Number (Liquid)plus, minus, times, divided_by, modulo, round, ceil, floor, abs, at_least, at_most, to_integer (Jekyll)
Date (mixed)date: '%Y-%m-%d', date: '%s', date_to_xmlschema, date_to_string

Try it yourself

  1. Add a tab. Create _tabs/liquid.md with layout: page, order: 5, icon: fas fa-flask, and a line of content. Add the matching label under tabs: in a local _data/locales/zh-CN.yml (override) or accept the English fallback. Rebuild and check the sidebar — that is sidebar.html looping site.tabs.
  2. Rewrite the reading time. Copy the theme’s _includes/read-time.html into this repo and change wpm from 180 to 300. Verify the include shadowing works.
  3. Change the related posts weights. Override _includes/related-posts.html and make tags worth 2 instead of 1. Watch the recommendation list change on an old post.
  4. Add a custom data file. Create _data/bookmarks.yml, then render it from a tab with a for loop over site.data.bookmarks.
  5. Break it on purpose. Delete an {% endif %} in a local include and run bundle exec jekyll b to see exactly how Jekyll reports a Liquid syntax error, including the file and line number.

References

本文由作者按照 CC BY 4.0 进行授权