Liquid
Learn how Masthead uses Liquid to render themes and discover the variables and filters available while building templates.
Masthead themes are rendered using the Liquid template language.
Liquid is responsible for generating the HTML of your website. Every template has access to a number of variables describing the current site, page and theme, allowing templates to render dynamic content without requiring custom backend code.
This guide focuses on the variables and filters provided by Masthead. For the Liquid language itself, refer to the official Liquid documentation.
Available variables
Masthead exposes several variables while rendering templates.
| Variable | Description |
|---|---|
site |
Information about the current site. |
theme |
The current theme and its configuration. |
page |
The page currently being rendered. |
pages |
All pages available on the site. |
post |
The current post. |
posts |
All posts available on the site. |
tags |
All tags used by the site’s posts. |
posts_by_tag |
Posts grouped by tag. |
body_html |
Rendered body of the current page or post. |
content |
Rendered content injected into the layout. |
The available variables depend on the template currently being rendered.
Site
The site object contains information about the current site.
<h1>{{ site.title }}</h1>
<p>{{ site.description }}</p>
Common properties include:
-
name -
title -
description -
slug
Theme
The theme object provides access to theme information and theme tokens.
<header style="color: {{ theme.tokens.accent }}">
It also contains information such as:
- Name
- Version
- Asset base URL
- Generated CSS
Pages and posts
Templates receive the page or post currently being rendered.
<h1>{{ page.title }}</h1>
or
<h1>{{ post.title }}</h1>
Collections are also available.
{% for post in posts %}
{{ post.title }}
{% endfor %}
Rendering page content
Markdown and HTML pages are rendered before reaching your template.
The rendered HTML is available through body_html.
<article>
{{ body_html }}
</article>
Layouts receive the fully rendered inner template through the content variable.
<main>
{{ content }}
</main>
Custom filters
Masthead provides a number of additional Liquid filters.
| Filter | Description |
|---|---|
asset_url |
Generates URLs for assets bundled with the theme. |
strftime |
Formats dates. |
iso8601 |
Formats timestamps as ISO-8601. |
where_tag |
Filters posts by tag. |
search |
Performs simple text searches. |
These filters behave the same during preview and on the hosted platform.
Escaping
Liquid does not automatically escape values.
When rendering user-provided text, use the escape filter where appropriate.
{{ page.title | escape }}
Values such as body_html and content already contain rendered HTML and should not be escaped.
Next steps
Liquid provides access to your site’s content and configuration.
The following guides explain how to work with assets, preview content and package your completed theme.