Skip to content
Honmaple
Documentation navigation

Template Functions

On this page

Content Lookups

Value or Function Description
pages Regular pages in the current language
hidden_pages Hidden pages in the current language
sections Sections in the current language
taxonomies Taxonomies in the current language
get_pages([lang]) Regular pages in the given language
get_hidden_pages([lang]) Hidden pages in the given language
get_sections([lang]) Sections in the given language
get_taxonomies([lang]) Taxonomies in the given 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
dict(k, v, ...) Create a map
slice(v, ...) Create a list
startsWith(s, prefix) Check a string prefix
load_data(path, format) Load from data/ or a URL
newScratch() Create temporary template storage

Omit the language argument to use the current language.

Page Collection Methods

OrderBy

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

Sort by date, modified, title, weight, or a front matter field.

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 %}
Property Description
group.Name Group name
group.Pages Pages in the group
group.Parent Parent group
group.Children Child groups

Limit

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

First and Last

{{ pages.First() }}
{{ pages.Last() }}

Reverse and Filter

{% for page in pages.Reverse() %}
{% for page in pages.FilterBy("'go' in tags") %}
{% for page in pages.OrderBy("weight asc, date desc") %}

Find neighboring articles in a collection:

{{ pages.Related(page).Prev }}
{{ pages.Related(page).Next }}
{{ pages.Related(page).HasPrev() }}
{{ pages.Related(page).HasNext() }}

Translation Functions

Function Description
i18n(key) Translate a string
T(key, args...) Translate and format with %d, %s, or %f
_(key, args...) Alias for formatted translation

Filters

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

Date layouts:

Layout Example Use
2006-01-02 2024-01-15 Date
15:04:05 20:35:00 Time
January 2, 2006 January 15, 2024 Long date
Mon, 02 Jan 2006 15:04:05 -0700 RSS pubDate
2006-01-02T15:04:05Z07:00 ISO 8601

Configuration Access

{{ config.title }}
{{ config.base_url }}
{{ config.author }}
{{ config.description }}
{{ config.GetString("params.my_key") }}

config represents the current language's settings. Access ordinary values with dot notation or use config.GetString(...).

Scratch

{{ scratch.Set("count", 1) | slient }}
{{ scratch.Add("count", 2) | slient }}
{{ scratch.Get("count") }}
{% set local = newScratch() %}
{{ local.Set("items", slice("a")) | slient }}
{{ local.Add("items", "b") | slient }}
{{ local.JSON("items") }}

Methods: Set, Get, GetOrSet, Add, and JSON.

Load Data

{% set data = load_data("links.yaml", "yaml") %}
{% set remote = load_data("https://example.com/data.json", "json") %}
{% set inferred = load_data("links.yaml", "") %}

Local paths are read from the site or theme's data/ directory. Formats are yaml, yml, toml, and json. An empty format is inferred from the file extension; other formats return plain text. Failed reads return nil and log a warning.

Assets Blocks

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

{% assets files="scss/style.scss" sass_compiler="dartsass" filters="cssmin" output="css/style.min.css" %}
<link rel="stylesheet" href="{{ asset_url }}">
{% endassets %}

Requires hooks.assets. See the assets hook for configuration.

Shortcodes

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

See Shortcodes for template locations and variables.