用户文档 开发者文档 | |

Filters

Filters transform a value before output. Applied with the pipe | operator inside {{ }} blocks. Multiple filters can be chained left to right.

{{ value | filter1 | filter2 "arg" }}

Unknown filter names pass the value through unchanged (no error is thrown).

date

Formats a date/datetime string using PHP's date() format codes.

{{ post.published_at | date "M d, Y" }}
{{ post.published_at | date "Y-m-d" }}
{{ post.published_at | date "F j, Y g:i a" }}

Accepts any string parseable by strtotime(). Format argument is required and must be double-quoted.

number_format

Formats a number with grouped thousands and decimal places.

{{ price | number_format 2 }}
{{ page_views | number_format 0 }}

Argument is the number of decimal places (integer, default 0 if omitted).

nl2br

Converts newlines to <br> tags. Applied before HTML-escaping, so the <br> tags are output raw.

{{ comment.body | nl2br }}

md5

Returns the MD5 hash of the value. Primarily used for Gravatar URLs.

<img src="https://www.gravatar.com/avatar/{{ user.email | strtolower | md5 }}?s=48">

count

Returns the number of items in an array, or the length of a string.

{{ posts | count }} posts
{% if tags | count > 5 %}...{% endif %}

excerpt

Truncates a string to the specified character length, appending ... if truncated. Strips HTML tags before truncating.

{{ post.body | excerpt 150 }}
{{ post.body | excerpt 250 }}

Argument is the character limit (integer). Truncation respects word boundaries.

default

Returns a fallback value if the original value is empty, null, or false.

{{ post.meta_title | default post.title }}
{{ options.title | default "Recent Posts" }}

Argument is the fallback expression. Can be a variable or a quoted string literal.

raw

Disables HTML escaping for this output expression. The value is inserted as-is into the output stream.

{{ post.rendered_html | raw }}

Use sparingly. Only use |raw on values you have explicitly sanitised.

strtolower

Converts the string to lowercase.

{{ tag.name | strtolower }}
{{ user.email | strtolower | md5 }}

strip_tags

Removes all HTML tags from the string. Useful for meta description generation from HTML body content.

{{ post.body | strip_tags | excerpt 160 }}

No argument. All tags are removed.

RedirectFilter

Registered as a global before filter. Checks incoming request paths against stored redirects and issues 301/302 responses. Admin (/admin/*) and API (/api/*) paths are excluded. Redirect mappings are cached for 1 hour.