Twig Filters

Herbie is using Twig Filters for modifying variables in layout and content files. In addition to the built-in filters of Twig itself, the following filters are available.

filesize

Returns file size in a human readable format (B, KB, MB, GB, TB, PB).

Parameter Type Description Default
[return] string The file size in human readable format
Example:
{{ 12345678|filesize }}

find

Find items of a traversable list by one or more selectors. Selectors are simple strings of text that specify fields and values. They are logical AND-connected and given as variadic arguments. Selectors in Herbie are loosely based around the idea and syntax of CSS attribute selectors. A selector can be one of the following:

=Equal to
!=Not equal to
<Less than
>Greater than
<=Less than or equal to
>=Greater than or equal to
*=Contains phrase/text
~=Contains all words
^=Starts with phrase/text
$=Ends with phrase/text
&Bitwise AND
Parameter Type Description Default
selectors string One or more selectors (optional, variadic)
[return] iterable The items matching the given selectors
Example:
{{ site.pageList|find("title^=this", "title~=is", "title$=great") }}

slugify

Returns a string slug for using as an URL segment.

Parameter Type Description Default
[return] string The slugified string
Example:
{{ "A string with spaces, Umlauts or special characters (?!&#)."|slugify }}

strftime

Formats a local time/date according to locale settings. This is a wrapper for the same-named PHP function.

Parameter Type Description Default
format string The format, see http://php.net/strftime %x
[return] string The formatted time or date
Example:
{{ "2022-09-13"|strftime("%Y-%m-%d") }}

visible

Filters the page tree by visible and active page items.

Parameter Type Description Default
[return] pageTree The filtered page tree
Example:
{{ site.pageTree|visible }}