Template functions and filters
Zorto registers custom template functions, filters, and tests on top of the Tera template engine. This page is the complete reference.
Functions #
Functions are called with named arguments inside templates.
get_url #
Returns the full permalink for a content path or static file.
Signature: get_url(path)
| Argument | Type | Description |
|---|---|---|
path | string | Content path (@/ prefix), static file path, or external URL |
Content paths use the @/ prefix to reference files in the content/ directory:
{{ get_url(path="posts/hello.md") }}
<!-- https://example.com/posts/hello/ -->
{{ get_url(path="posts/_index.md") }}
<!-- https://example.com/posts/ -->
In content files, prefix paths with @/ for build-time link validation.
Static file paths are resolved relative to the site root:
{{ get_url(path="/img/photo.png") }}
<!-- https://example.com/img/photo.png -->
External URLs are returned as-is:
{{ get_url(path="https://github.com") }}
<!-- https://github.com -->
get_section #
Loads a section object by its _index.md path. Returns the full section with its pages, useful for cross-referencing content.
Signature: get_section(path)
| Argument | Type | Description |
|---|---|---|
path | string | Relative path to the section’s _index.md |
{% set posts = get_section(path="posts/_index.md") %}
{% for page in posts.pages %}
<a href="{{ page.permalink }}">{{ page.title }}</a>
{% endfor %}
The returned section object has all the fields documented in the frontmatter reference (title, pages, path, permalink, extra, etc.).
Warning
get_section raises an error if the path does not match any loaded section. Double-check the path matches the actual _index.md location.
get_taxonomy_url #
Returns the permalink for a specific taxonomy term page.
Signature: get_taxonomy_url(kind, name)
| Argument | Type | Description |
|---|---|---|
kind | string | Taxonomy name (e.g. "tags", "categories") |
name | string | Term value (e.g. "rust") |
{{ get_taxonomy_url(kind="tags", name="rust") }}
<!-- https://example.com/tags/rust/ -->
The term name is slugified to form the URL (e.g. "My Tag" becomes my-tag).
now #
Returns the current local timestamp as a string in YYYY-MM-DDTHH:MM:SS format.
Signature: now()
<footer>Built at {{ now() }}</footer>
<!-- Built at 2026-04-04T14:30:00 -->
Filters #
Filters transform values using the pipe (|) syntax. Zorto provides these custom filters in addition to Tera’s built-in filters.
date #
Formats a date string using chrono format specifiers.
| Parameter | Type | Default | Description |
|---|---|---|---|
format | string | "%Y-%m-%d" | Output format string |
Accepts YYYY-MM-DD and YYYY-MM-DDTHH:MM:SS input formats. Returns the original string unchanged if parsing fails.
{{ page.date | date(format="%B %d, %Y") }}
<!-- June 15, 2025 -->
{{ page.date | date(format="%Y") }}
<!-- 2025 -->
pluralize #
Returns "s" when the value is not 1, empty string when it is 1. Useful for English pluralization.
{{ count }} item{{ count | pluralize }}
<!-- "1 item" or "5 items" -->
Works with integers and floats (floats are truncated to integers).
slice #
Extracts a sub-array from an array.
| Parameter | Type | Default | Description |
|---|---|---|---|
start | int | 0 | Start index (inclusive) |
end | int | array length | End index (exclusive) |
{% for page in section.pages | slice(end=5) %}
<!-- First 5 pages -->
{% endfor %}
{% for page in section.pages | slice(start=2, end=7) %}
<!-- Pages 3 through 7 -->
{% endfor %}
Out-of-bounds values are clamped to the array length.
Tests #
Tests check conditions using the is keyword.
starting_with #
Tests whether a string starts with the given prefix.
{% if page.path is starting_with("/docs") %}
<!-- Documentation page -->
{% endif %}
Tera built-in filters #
Zorto inherits all of Tera’s built-in filters. Commonly used ones:
| Filter | Description | Example |
|---|---|---|
safe | Mark HTML as safe (no escaping) | {{ page.content | safe }} |
length | Array or string length | {{ items | length }} |
upper | Uppercase a string | {{ title | upper }} |
lower | Lowercase a string | {{ title | lower }} |
replace | Replace substring | {{ title | replace(from="old", to="new") }} |
truncate | Truncate string | {{ desc | truncate(length=100) }} |
default | Fallback value | {{ author | default(value="Anonymous") }} |
join | Join array to string | {{ tags | join(sep=", ") }} |
first | First element | {{ items | first }} |
last | Last element | {{ items | last }} |
reverse | Reverse array | {{ items | reverse }} |
sort | Sort array | {{ items | sort }} |
json_encode | Serialize to JSON | {{ data | json_encode }} |
See the Tera documentation for the complete list.
Further reading #
- Templates concept — template hierarchy and context variables
- Advanced templating — macros, block inheritance, config.extra access
- Frontmatter reference — all fields available on
pageandsectionobjects