Useful Twig Functions and Filters

Filters

Numbers

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 linebreaks
  • replace: Replace a string.
  • reverse: Reverse a string
  • slice: 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 arrays
  • reverse: Reverse an array.

Functions

  • date: Converts an argument to a date to allow date comparison
  • max: returns the highest value of a sequence or a set of values
  • min: returns the lowest value of a sequence or a set of values
  • random: The random function returns a random value depending on the supplied parameter type.
  • range: Returns a list containing an arithmetic progression of integers: