Converts a string to an md5 hash.
{{ 'foo' | md5 }}
{# 'acbd18db4cc2f85cedef654fccc4a4d8' #}
Converts a string to an sha1 hash.
{{ 'foo' | sha1 }}
{# '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' #}
Converts a string to an sha512 hash.
{{ 'foo' | sha512 }}
{# '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae' #}
Use the time_diff
filter to render the difference between a date and now.
{{ entry.postDate | time_diff }}
{# '2 days ago' #}
Converts a string to the plural form.
{{ 'result' | pluralize }}
{# 'results' #}
{{ 'results' | pluralize(1) }}
{# 'result' #}
{{ entries|length }} {{ 'results' | pluralize(entries|length) }}
{# '1 result' or '2 results' #}
Converts a string to the singular form.
{{ 'cars' | singularize }}
{# 'car' #}
{{ 'foo_bar' | camelize }}
{# 'FooBar' #}
{{ 'foo_bar' | dasherize }}
{# 'foo-bar' #}
{{ 'employee_salary' | humanize }}
{# 'Employee salary' #}
{{ 'author_id' | humanize }}
{# 'Author' #}
{{ 1 | ordinalize }}
{# '1st' #}
{{ 2 | ordinalize }}
{# '2nd' #}
{{ loop.index | ordinalize }}
{# '3rd' #}
{{ 'x-men: the last stand' | titleize }}
{# 'X Men: The Last Stand' #}
{{ 'raiders_of_the_lost_ark' | titleize }}
{# 'Raiders Of The Lost Ark' #}
{{ 'FooBar' | underscore }}
{# 'foo_bar' #}
Needs documentation
Use the localizeddate
filter to format dates into a localized string representating the date.
{{ entry.postDate | localizeddate('medium', 'none', locale) }}
{# 'Nov 13, 2012' #}
Argument | Options | Default | Description | |
---|---|---|---|---|
date_format |
'none' |
Do not include this element | 'medium' |
The date format. |
'short' |
Most abbreviated style, only essential data (12/13/52 or 3:30pm) | |||
'medium' |
Medium style (Jan 12, 1952) | |||
'long' |
Long style (January 12, 1952 or 3:30:32pm) | |||
'full' |
Completely specified style (Tuesday, April 12, 1952 AD or 3:30:42pm PST) | |||
time_format |
Same formats as listed above. | 'medium' |
The time format. | |
locale |
- | null |
The locale used for the format. If NULL is given, Twig will use Locale::getDefault(). | |
timezone |
- | null |
The date timezone | |
format |
- | null |
Optional pattern to use when formatting or parsing. Possible patterns are documented in the ICU user guide. |
Internally, this filter uses the PHP IntlDateFormatter::create() function for the date.
Needs documentation
Centers the value in a field of a given width.
{{ 'middle' | center(40) }}
{# ' middle ' #}
Use the truncate
filter to cut off a string after limit is reached.
{{ "Hello World!" | truncate(5) }}
{# 'Hello...' #}
{{ "Hello World!" | truncate(7, true) }}
{# 'Hello World!' #}
{{ "Hello World!" | truncate(7, false, "??") }}
{# 'Hello W??' #}
Use the wordwrap
filter to split your text in lines with equal length.
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing" | wordwrap(10) }}
Lorem ipsu
m dolor si
t amet, co
nsectetur
adipiscing