Skip to content
Honmaple
Documentation navigation

Templates

On this page

Snow uses Pongo2, with Django/Jinja2-style syntax.

Basic Syntax

{# A comment #}
<h1>{{ page.Title }}</h1>
<p>{{ page.Date | date:"2006-01-02" }}</p>

{% if page.Draft %}
  <span>Draft</span>
{% endif %}

{% for page in pages %}
  <li><a href="{{ page.Path }}">{{ page.Title }}</a></li>
{% endfor %}

{% i18n "tags" %}
{{ _("Total: %d articles", 12) }}

Global Variables

Variable Description
config Site configuration
pages Regular pages
hidden_pages Hidden pages
sections Sections
taxonomies Taxonomies
page Current page in page templates
section Current section in section templates
term Current term in term templates
taxonomy Current taxonomy in list templates
terms Reference to taxonomy.Terms in list templates
paginator Pagination context

Page Variables

Property Type Description
page.Title string Title
page.Slug string URL slug
page.Lang string Language
page.Date time.Time Creation date
page.Modified time.Time Modification date
page.Path string Relative URL
page.Permalink string Absolute URL
page.Summary string Summary
page.Content string Rendered HTML
page.RawContent string Original content
page.WordCount int64 Word count
page.ReadingTime int64 Estimated reading time in minutes
page.FrontMatter.{xxx} any Custom metadata
page.Formats Formats Additional formats
page.Section *Section Owning section
page.Ancestors() Sections Sections from the owning section to the home section
page.Draft bool Draft status
page.Hidden bool Hidden status

Section Variables

Property Description
section.Title Title
section.Slug Slug
section.Lang Language
section.Path Relative URL
section.Permalink Absolute URL
section.Content Rendered content
section.RawContent Original index content
section.WordCount Word count
section.ReadingTime Estimated reading time in minutes
section.HiddenPages Hidden pages
section.Pages Regular pages
section.Children Child sections
section.Parent Parent section
section.Ancestors() Sections from the parent to the home section
section.Formats Additional formats

Taxonomy Variables

Property Description
taxonomy.Name Name
taxonomy.Lang Language
taxonomy.Path Relative URL
taxonomy.Permalink Absolute URL
taxonomy.Terms Terms
term.Name Term name
term.Slug Slug
term.Path Relative URL
term.Permalink Absolute URL
term.Pages Pages
term.Children Child terms
term.Parent Parent term
term.Formats Additional formats
term.Taxonomy Owning taxonomy

Global Functions

Function Description
get_pages([lang]) All pages in a language
get_hidden_pages([lang]) Hidden pages in a language
get_sections([lang]) Sections in a language
get_taxonomies([lang]) Taxonomies in a language
get_page(path, [lang]) Find a page
get_page_url(path, [lang]) Page absolute URL
get_section(path, [lang]) Find a section
get_section_url(path, [lang]) Section absolute URL
get_taxonomy(name, [lang]) Find a taxonomy
get_taxonomy_url(name, [lang]) Taxonomy absolute URL
get_taxonomy_term(taxonomy, name, [lang]) Find a term
get_taxonomy_term_url(taxonomy, name, [lang]) Term absolute URL
i18n(key) Translate
T(key, args...) Translate with formatting
_(key, args...) Translate with formatting
dict(k, v, ...) Create a map
slice(v, ...) Create a list
startsWith(s, prefix) Check a prefix
load_data(path, format) Load data from data/ or a URL
newScratch() Create temporary template storage

Language arguments are optional and default to the current language.

Page Collection Methods

pages and section.Pages are Pages collections with chainable methods.

OrderBy

{% for page in pages.OrderBy("date desc, title asc") %}

Fields include date, modified, title, weight, and custom front matter.

GroupBy

{% for group in pages.GroupBy("date:2006-01").OrderBy("name desc") %}
  <h2>{{ group.Name }}</h2>
  {% for page in group.Pages %}
    <li>{{ page.Title }}</li>
  {% endfor %}
{% endfor %}

GroupBy returns temporary PageGroups. Group by a front matter field or date:{layout}. Group ordering supports name and count; groups expose Name, Pages, Parent, and Children.

Limit

{% for page in pages.Limit(5) %}

Filters

Filter Description Example
truncate:N Limit to N characters {{ text | truncate:100 }}
date:"layout" Format a date {{ page.Date | date:"2006-01-02" }}
lower Lowercase {{ text | lower }}
upper Uppercase {{ text | upper }}
split:"sep" Split a string {{ value | split:"," }}
encrypt:"pw" Encrypt with a password {{ content | encrypt:"123" }}
parser:"markdown" Render with an enabled content parser {{ text | parser:"markdown" }}
unmarshal:"yaml" Parse YAML, TOML, or JSON {{ text | unmarshal:"yaml" }}
jsonify Serialize to JSON {{ page.FrontMatter | jsonify }}
absURL Make an absolute URL {{ "posts/" | absURL }}
relURL Make a relative URL {{ "/posts/" | relURL }}
slient Discard output, retaining side effects {{ scratch.Set("k", 1) | slient }}

Date layouts include 2006-01-02, 2006/01/02, January 2, 2006, and the RSS layout Mon, 02 Jan 2006 15:04:05 -0700.

Shortcodes

<shortcode youtube id="xxx" />
<shortcode code lang="python">
print("hello")
</shortcode>

See Shortcodes for templates, parameters, and context.

Assets

{% assets css %}
<link rel="stylesheet" href="{{ config.base_url }}/{{ asset_url }}">
{% endassets %}

Requires hooks.assets. See the assets hook.

Scratch and Data

{{ scratch.Set("count", 1) | slient }}
{{ scratch.Add("count", 2) | slient }}
{{ scratch.Get("count") }}
{% set data = load_data("links.yaml", "yaml") %}

scratch is shared temporary storage; use newScratch() for local storage. load_data reads from data/ or an HTTP(S) URL. Supported formats are yaml, yml, toml, and json; an empty format is inferred from the extension.

Configuration Access

<title>{{ config.title }}</title>
<base href="{{ config.base_url }}">
<meta name="author" content="{{ config.author }}">