Twig Filters
Herbie is using Twig Filters for modifying variables in layout and content files. The following filters are available.
format_bytes
Formats a byte count in a human readable format (B, KB, MB, GB, TB, PB). Uses 1024-based units and rounds to one decimal place. Values <= 0 return "0", a single byte returns "1 Byte", and the largest unit is PB.
| [return] | Description |
| string | The byte count in human readable format |
{{ 12345678|format_bytes }}
slugify
Converts a string into a URL-friendly slug, a simplified text suitable for use in URL segments.
| [return] | Description |
| string | The slug |
{{ "A string with spaces, Umlauts or special characters (?!&#)."|slugify }}
spaceless
Removes whitespace between HTML tags. Herbie provides this filter because Twig deprecated the filter of the same name in 3.12.
| [return] | Description |
| string | The input without whitespace between HTML tags |
{{ "<div> <strong>foo</strong> </div>"|spaceless }}
twigify
Renders a string as a Twig template in the current context and returns the result.
| [return] | Description |
| string | The rendered string |
{{ "Hello {{ page.title }}"|twigify }}
Built-in Filters
In addition to the filters mentioned above, Twig's built-in filters are of course also available. Please note that some of the filters may require the installation of additional Composer packages. See the official Twig documentation for the complete list and examples.