lower
Converts letters to lowercase.
upper
Converts letters to uppercase.
wordcount
Returns the word count.
capitalize
Capitalizes the first letter of each word in a sentence.
title
Capitalizes the first letter of every word.
replace
Replaces a string.
{{ name | replace(from="Robert", to="Bob")}}
regex_replace
Regular expression replacement.
{{ name | regex_replace(from="\d+", to="$1")}}
addslashes
Escapes quotes.
{{ set value = "I'm using Daobox" }}
{{ value | addslashes }}
Output: I\\'m using Daobox
slugify
Converts to a URL-friendly slug string.
{{ set value = "-Hello world! " }}
{{ value | slugify }}
Output: hello-world
trim
Trims whitespace from both ends.
trim_start
Trims whitespace from the left side.
trim_end
Trims whitespace from the right side.
trim_start_matches
Trims characters matching a regex pattern from the left side.
{{ set value = "//a/b/c//" }}
{{ value | trim_start_matches(pat="//") }}
Output: a/b/c//
trim_end_matches
Trims characters matching a regex pattern from the right side.
{{ set value = "//a/b/c//" }}
{{ value | trim_start_matches(pat="//") }}
Output: //a/b/c
truncate
Truncates a string to the specified length. If the string is shorter than the limit, it is kept intact. After truncation, "..." is appended to the end; the suffix can be changed via the end parameter.
{{ value | truncate(length=10, end="") }}
linebreaksbr
Replaces newline characters (\n, \r\n) with <br>.
spaceless
Removes whitespace and newlines inside HTML tags.
{% set value = "<p>\n<a> </a>\r\n </p>" %}
{{ value | spaceless }}
Output: <p><a></a></p>
striptags
Strips HTML tags.
{% set value = "<b>Joel</b>" %}
{{ value | striptags }}
Output: Joel
first
Returns the first element of a list. Returns an empty string if the list is empty.
last
Returns the last element of a list. Returns an empty string if the list is empty.
nth
Returns the N-th element of a list (0-based index). Returns an empty string if the list is empty.
{{ value | nth(n=2) }}
join
Joins strings in a list with a separator.
{% set value = ['a', 'b', 'c'] %}
{{ value | join(sep=" // ") }}
Output: a // b // c
length
Returns the length of a list, object, or string.
index_of
Returns the position of the specified element in a list, starting from 0.
Parameters
| Parameter | Meaning | Type | Optional | Notes |
|---|---|---|---|---|
| search | The list to search | list of elements |
Returns
An integer. Returns -1 if not found.
e.g.
{% set s = "hello" %}
{{ s | index_of(search=["a", "b", "hello"]) }}
{# output: 2 #}
reverse
Returns a string or list in reverse order.
sort
Sorts a list. Elements in the list must be sortable.
- Numbers are sorted by value.
- Strings are sorted by ASCII order.
- Lists are sorted by length.
- Booleans: true=1, false=0.
If list elements are objects (key-value pairs), you can specify the attribute to sort by:
{% set people = [
{
"name": ["daobox", "yu"],
"age": 30
}
] %}
{# Sort by first name #}
{{ people | sort(attribute="name.0") }}
{# Sort by age #}
{{ people | sort(attribute="age") }}
unique
Deduplicates a list. Usage is the same as sort. When the reference value is a string, you can use case_sensitive to specify whether to ignore case.
{{ people | unique(attribute="age") }}
{{ people | unique(attribute="name.1", case_sensitive="true") }}
slice
Slices a list. Use the start and end parameters to specify the start and end indices (0-based). Returns a sublist from start (inclusive) to end (exclusive). Both parameters can be omitted, defaulting to the list boundaries.
{% for i in my_arr | slice(end=5) %}
{% for i in my_arr | slice(start=1) %}
{% for i in my_arr | slice(start=1, end=5) %}
Use negative indices to count from the end.
{% set my_array = [1, 2, 3, 4, 5] %}
{{ my_arr | slice(end=-2) }}
Result: [1, 2, 3]
group_by
Groups a list. The attribute parameter specifies the grouping key. Returns an object (key-value pairs) where each key is an attribute value and each value is a list of elements with that attribute. Elements missing the grouping attribute are ignored.
Object definition example (pseudocode):
Author {
name: String,
};
Post {
content: String,
year: u32,
author: Author,
}
posts=[Post, Post]
Group by year:
{{ posts | group_by(attribute="year") }}
Group by author.name:
{% for name, author_posts in posts | group_by(attribute="author.name") %}
{{ name }}
{% for post in author_posts %}
{{ post.year }}: {{ post.content }}
{% endfor %}
{% endfor %}
Custom grouping:
{% set map = section.pages | group_by(attribute="year") %}
{% set_global years = [] %}
{% for year, ignored in map %}
{% set_global years = years | concat(with=year) %}
{% endfor %}
{% for year in years | reverse %}
{% set posts = map[year] %}
{% endfor %}
filter
Filters a list. Returns only elements whose attribute equals the specified value. Elements missing the attribute or with a null/empty value are ignored.
The attribute parameter is required. The value parameter can be omitted, which means elements with a null/empty attribute value are filtered out.
Author {
name: String,
};
Post {
content: String,
year: u32,
author: Author,
draft: bool,
}
{{ posts | filter(attribute="draft", value=true) }}
{{ posts | filter(attribute="author.name", value="Vincent") }}
map
Extracts the specified attribute from each element and returns a list.
Name(String, String);
Person {
name: Name,
age: u32,
}
Return all ages:
{{ people | map(attribute="age") }}
concat
Appends one or more elements to a list.
{{ posts | concat(with=drafts) }}
urlencode
Encodes a string into a safe URL encoding. Per RFC3986, / is not encoded.
{% set value = "/foo?a=b&c=d" %}
{{ value | urlencode }}
Output: /foo%3Fa%3Db%26c%3Dd
urlencode_strict
Same as urlencode, but also encodes /.
round
Rounds a floating-point number.
Parameters:
method: rounding method.common: round half up (default)ceil: round upfloor: round down
precision: number of decimal places. Defaults to 0.
filesizeformat
Converts an integer to a human-readable file size format.
{{ num | filesizeformat }}
date
Converts a timestamp or date to the specified date format.
{{ ts | date }}
{{ ts | date(format="%Y-%m-%d %H:%M") }}
The timezone parameter can be specified; it defaults to Asia/Chongqing when omitted.
escape
Escapes special characters.
&=>&<=><>=>>"=>"'=>'/=>/
escape_xml
Escapes XML special characters.
&=>&<=><>=>>"=>"'=>'
safe
By default, content output undergoes HTML special character escaping. The safe filter prevents HTML escaping of the final output.
get
Retrieves a value from an object by key, supporting multi-level access. The default parameter is optional and specifies the default value to return when the key does not exist.
{{ sections | get(key="posts/content", default="default") }}
split
Splits a string into a list using the specified delimiter.
{{ path | split(pat="/") }}
int
Converts a value to an integer. Recognizes prefixes 0b, 0o, 0x.
Parameters:
default: optional. The default value to use on conversion error.base: optional. The integer base. Valid values:10,2,8,16.
float
Converts to a floating-point number. The default parameter can specify the default value to use on conversion error.
json_encode
Converts to a standard JSON string. For security reasons, Everkm Publish automatically escapes HTML characters, so you can combine it with safe to disable escaping.
{{ value | json_encode | safe }}
Parameters:
pretty: optional. Outputs a pretty-printed JSON string. Valid values:trueorfalse.
{{ value | json_encode(pretty=true) | safe }}
default
Provides a default value for undefined variables.
Note: only effective for undefined variables. Does not apply to empty strings (""), 0, or false.
I would like to read more {{ "" | default (value="Louise Michel") }}!
Output: I would like to read more !
json
Converts text to a JSON object.
{{ value | json }}
markdown_to_html
Alias: md_to_html. Converts Markdown text to HTML.
{{ value | md_to_html }}
thumbnail
Automatically generates a thumbnail.
Parameters
| Key | Meaning | Type | Optional | Notes |
|---|---|---|---|---|
| wxh | Max width x max height | string | yes | When omitted, falls back to config cfg.thumbnail.default_dimension; if also unset, uses the original image. You can specify only height or width, e.g., 400x (width limited to 400px) or x300 (height limited to 300px). |
Returns
Thumbnail information.
| Key | Meaning | Type | Optional | Notes |
|---|---|---|---|---|
| url | Thumbnail URL | string | ||
| width | Thumbnail width | integer | ||
| height | Thumbnail height | integer |
object_keys
Gets a list of an object's keys.
Returns
[
"<key>",
]
object_values
Gets a list of an object's values.
Returns
[
<value>,
]