Useful Twig Functions and Filters
Filters
Numbers
abs
:round
:number_format
: Applies number formatting for things like thousands separators.
Dates
Text
Casing
capitalize
: Makes the first letter capital, and all the other lowercase.title
: Apply title-case logic.lower
: Makes the string lower case.upper
:
Other string filters
default
: Fallback if the original value is empty or non-existant.nl2br
: Converts new lines into HTML linebreaksreplace
: Replace a string.reverse
: Reverse a stringslice
: Slice the string into a subset.split
: Split the string into an array, by a delimiter.striptags
:trim
: Remove starting and trailing whitespace from the string.url_encode
:length
: Return the string's length.
Arrays and Objects
sort
: Sort the values of an array.length
: Returns the array or object's length.merge
: Merge two arrays together.slice
: Return a subset of two arraysreverse
: Reverse an array.
Functions
date
: Converts an argument to a date to allow date comparisonmax
: returns the highest value of a sequence or a set of valuesmin
: returns the lowest value of a sequence or a set of valuesrandom
: The random function returns a random value depending on the supplied parameter type.range
: Returns a list containing an arithmetic progression of integers:
Updated less than a minute ago