Twig Filters

abs

Returns an absolute value for a number.

{{ number|abs }}

View details

base64_decode

Decodes a base64 encoded value.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ value|base64_decode }}

View details

base64_encode

Base 64 encodes a value. The value must be a string.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ value|base64_encode }}

View details

batch

The batch filter breaks up an array into groups of arrays with the given number of items.

{% for row in items|batch(3, 'No item') %}
{% endfor %}

View details

camel

Takes a series of words and camel cases them.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|camel }}

View details

capitalize

Changes the first letter of the value to be uppercase. All other characters will be lower case.

{{ variable|capitalize }}

View details

ceiling

Rounds up a number.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ number|ceiling }}

View details

ceil

Alias to the ceiling filter.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ number|ceil }}

View details

country_abbreviation

Gets the 2 letter country abbreviation for the variable value if the variable value is a valid country or country abbreviation.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|country_abbreviation }}

View details

country_data

Gets an array of country data for the variable value if the variable value is a valid country or country abbreviation.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set data = variable|country_data %}

View details

country_name

Gets the full country name for the variable value if the variable value is a valid country or country abbreviation.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|country_name }}

View details

date

Formats a date to a given format.

{{ post.publishedOnTimestamp|date('M d, Y') }}

View details

date_diff

Gets the difference between now (or a passed date) and the date value the filter is applied to.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ post.createdOnTimestamp|time_ago }}

View details

date_modify

Modifies a date based on the passed modifier.

{{ post.publishedOnTimestamp|date_modify('+ 1 day')|date('m/d/Y') }}

View details

debug

Outputs the results of a variable in a debug statement. Useful for development.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ post|debug }}

{{ form.fields|debug('Form fields') }}

View details

debug_email

Outputs the results of a variable in a debug statement specifically formatted for using in emails. Useful when developing form notification emails.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ form.fields|debug_email }}

{{ form.fields|debug_email('Form fields') }}

View details

default

Returns the passed default value if the variable is undefined or empty, otherwise, it returns the variable value.

{{ variable|default('My Default Value') }}

View details

embed_media

Takes a string and looks for any URLs for embeddable resources (YouTube videos for example) and using the oEmbed protocol converts the URL into the appropriate embed code.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|embed_media }}

View details

escape

Escapes a string for final output. Useful for user-entered data where you're not sure that the data is safe.

{{ variable|escape }}

View details

escape_quotes

Escapes single and double quotes with a backslash "\". By default it will escape both double and single quotes but you can specify which one you want to escape.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|escape_quotes }}

{{ variable|escape_quotes('single') }}

{{ variable|escape_quotes('double') }}

View details

file_basename

Parses the file path and returns just the basename value.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ '/path/to/my/file.pdf'|file_basename }}

View details

file_dirname

Parses the file path and returns just the dirname value.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ '/path/to/my/file.pdf'|file_dirname }}

View details

file_extension

Parses the file path and returns just the file extension value.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ '/path/to/my/file.pdf'|file_extension }}

View details

file_name

Parses the file path and returns just the filename value.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ '/path/to/my/file.pdf'|file_name }}

View details

file_url

Prepends the CDN or S3 URL of the file to the file path. This also allows you to use the image CDN pipeline to modify the image.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
<link rel="icon" type="image/png" href="{{ 'favicon.ico'|file_url }}">

View details

first

Returns the first value of an array, hash or string.

{{ [1, 2, 3, 4]|first }}

View details

float

Converts the value to a float number.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|float }}

View details

floor

Rounds a number down. You can also specify a precision.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ number|floor }}

{{ number|floor(2) }}

View details

format

Formats a string by replacing the placeholders with the specified values.

{{ 'I like %s and %s'|format('icecream', 'pickles') }}

View details

html2text

Converts an HTML string to plain text.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ htmlVariable|html2text }}

View details

html_entities

Converts HTML entities to their entity value.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ '<p><b>All</b> HTMl code will be converted</p>'|html_entities }}

View details

html_special_characters

Converts only special characters to their HTML entity. (& " ' < >)

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ 'Only &, <, >, " and \' will be converted'|html_special_chars }}

View details

inject_html

Inserts an HTML snippet immediately before a closing block level tag (</p> </div>) or a closing span tag </span> if they are the last HTML tag in the variable value. If they are not then the HTML snippet is simply appended to the variable value.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ post.abstract|inject_html(' <a href="' ~ post.url ~ '">Read more<a>') }}

View details

image_url

Prepends the CDN or S3 URL of the image to the image path. This also allows you to use the image CDN pipeline to modify the image.

This is an alias to the file_url filter. It does the same thing as that filter.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
<img src="{{ image|file_url({width: 300, height: 100}) }}">

View details

integer

Converts the value to an integer.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|integer }}

View details

int

Alias to the integer filter.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|int }}

View details

intersect

Returns an array containing only the values that are in both arrays.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set myPets = ['dog', 'cat', 'snake', 'elephant', 'fish'] %}
{% set yourPets = ['snake', 'camel', 'fish', 'shark'] %}
{% set samePets = myPets|intersect(yourPets) %}

View details

intersect_assoc

Returns an array containing only the values that are in both arrays. The array keys are also used in the comparison.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set myColors = {'g': 'green', 'b': 'blue', 'y': 'yellow', 'r': 'red'} %}
{% set yourColors = {'b': 'brown', 'g': 'green', 'x': 'yellow'} %}
{% set sameColors = myColors|intersect_assoc(yourColors) %}

View details

join

Concatenates the values of an array into a string, optionally separated by the passed separator.

{{ array|join(' | ') }}

View details

json

Alias to the json_encode filter.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ post.postTitle|json }}

View details

json_decode

Returns the JSON representation of a value. If the value is a string then it'll be wrapped in double-quotes. If it's a number or boolean then no change is made. If it's an array or object then it'll be converted to the JSON equivalent. 

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set data = jsonString|json_decode %}

View details

json_encode

The json_encode filter encodes the value as a JSON compatible value.

{{ post.postTitle|json_encode }}

View details

kebab

Takes a string and creates a lowercase version of it with words separated by dashes instead of spaces. Useful for creating anchor links.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ "Bob Smith"|kebab }}

View details

keys

Returns the keys of an array.

{% for key in array|keys %}
{% endfor %}

View details

kintersect

Returns an array containing only the values that are in the first array whose keys are also in the second array. The values are not compared.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set myColors = {'blue': '5', 'red': '15', 'green': '2'} %}
{% set yourColors = {'red': '2', 'black': '3', 'green': '30'} %}
{% set same = myColors|kintersect(yourColors) %}

View details

kmerge

Merges two arrays together while preserving their keys (including numeric keys).

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set array = {1: 'One', 2: 'Two', 3: 'Three', 'four': 'Four string'} %}
{% set array2 = {1: 'One2', 2: 'Two2', 4: 'Four', 5: 'Five'} %}
{% set array = array|kmerge(array2) %}

View details

kmerge_deep

Merges two arrays together recursively while preserving their keys (including numeric keys).

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set array = {1: 'One', 2: 'Two', 3: ['Three', 'Three is great'], 'four': 'Four string', 'five': {32: 'numeric key', 'string': 'string key'}} %}
{% set array2 = {2: 'New Two', 3: ['Another three'], 'four': 'New Four string', 'five': {32: 'new numeric key'}, 'six': 'I will stay'} %}
{% set array = array|kmerge_deep(array2) %}

View details

krsort

Sorts an array or hash by its keys in reverse order (Z-A).

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set array = array|krsort %}

View details

ksort

Sorts an array or hash by its keys.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set array = array|ksort %}

View details

last

Returns the last element of an array, hash or string.

{{ [1, 2, 3, 4]|last }}

View details

lcfirst

Lowercases the first letter of a string.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|lcfirst }}

View details

length

Returns the number of items in an array or hash, or the length of a string.

{{ post.postTitle|length }}

View details

lower

Converts the string value to all lower case.

{{ 'I SHOULD BE LOWERCASE'|lower }}

View details

ltrim

Trims the begining of a string for whitespace or a specific character.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ string|ltrim }}

View details

map

The map filter lets you apply a function to each item in an array or object to return a new value. 

The function can either output content, or you can return a value to a variable. If you return a value the new variable value will be an array.

{% set categoryIds = post.categories|map(category => category.id) %}

View details

md5

Converts the string to an MD5 hash.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set hash = post.postTitle|md5 %}

View details

md5_hmac

Converts the string to an MD5 hash using the HMAC method.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set hash = post.postTitle|md5_hmac('secret_key') %}

View details

merge

Merges an array with another array.

{% set data = ['apple', 'bannana', 'orange']|merge(['grapes', 'pinapple']) %}

View details

merge_deep

Merges two arrays together recursively.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set array = {1: 'One', 2: 'Two', 3: ['Three', 'Three is great'], 'four': 'Four string', 'five': {32: 'numeric key', 'string': 'string key'}} %}
{% set array2 = {1: 'One2', 2: 'Two2', 4: 'Four', 5: 'Five'} %}
{% set array = array|merge_deep(array2) %}

View details

nl2array

Splits a string on new line characters and returns an array of the string parts.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set data = var|nl2array %}

View details

nl2br

Converts new line characters in a string to <br> tags.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ string|nl2br }}

View details

nlc2array

Splits a string on new line characters or commas an returns an array of the string parts.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set data = var|nlc2array %}

View details

number_format

Formats a number to have a certain number of decimal points, a specific decimal point character, and thousands separator.

{{ 3024.2|number_format(2) }}

View details

pascal

Takes a series of words and PascalCases them.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|pascal }}

View details

push

Pushes a value to the end of an array. It can sometimes be simpler than using the merge filter.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set animals = [] %}
{% set animals = animals|push('dog') %}
{% set animals = animals|push('cat') %}
{% set animals = animals|push('fish') %}

View details

raw

Marks a value as "safe" meaning it won't be auto escaped.

{% autoescape %}
    {{ var|raw }}
{% endautoescape %}

View details

regex_filter

Replaces values within a string by a regular expression and returns only the (possibly transformed) subjects where there was a match.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set new = ['x', 'y', 'z', 'm', 'e', '3', '10']|regex_filter(['/\\d/', '/[x-z]/'], ['$0 is a NUMBER ', '$0 is a LETTER ']) %}

View details

regex_quote

Quotes regular expression characters.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ value|regex_quote() }}
{{ value|regex_quote('#') }}

View details

regex_replace

Replaces values within a string, or an array of strings, by a regular expression or an array of regular expressions.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ 'Make me a kebab string'|lower|regex_replace('/[^\\w]+/', '-') }}

View details

regex_split

Splits the string value by a regular expression.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set parts = 'Separate this sentence    by spaces, commas, and    more spaces.'|regex_split('/[\\s,]+/') %}

View details

replace

Replaces the specified text or placeholders with other values.

Aptuitiv's replace filter overrides the Twig replace filter to add support for passing a string value for search and replace.
{{ 'I like %this% and %that%.'|replace({'%this%': 'apples', '%that%': 'bananas'}) }}

{{ variable|replace({'-': '%ndash;'}) }}

{{ 'Hi my name is Bob'|replace('Bob', 'Sam') }}

View details

reverse

Reverses an array, hash or string.

{% for post in posts|reverse %}
{% endfor %}

View details

round

Rounds a number to a given precision using a specific rounding method.

{{ 42.55|round }}

{{ 42.55|round(1) }}

{{ 42.55|round(1, 'ceil') }}

View details

rsort

Sorts an array in reverse order.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set array = array|rsort %}

View details

rtrim

Strip whitespace (or other characters) from the end of a string.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ var|rtrim }}

View details

shuffle

Randomizes the order of elements in an array and returns the result.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set newValue = value|shuffle %}

View details

slice

Extracts a slice of an array, hash or string.

{% for i in [1, 2, 3, 4]|slice(1, 2) %}
{% endfor %}

View details

snake

Takes a string and creates a lowercase version of it with words separated by underscores instead of spaces.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ "Apples and Pears"|snake }}

View details

sort

Sorts an array.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set array = array|sort %}

View details

sort_by_key

Sort a multi-dimensional array by a specific value in a child array. The value is specified by the array key. The sorting is case sensitive.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set myArray = myArray|sort_by_key('age') %}
{% set myArray = myArray|sort_by_key('age', 'desc') %}

View details

sort_ci_by_key

Sort a multi-dimensional array in a case insensitive way by a specific value in a child array. The value is specified by the array key.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set myArray = myArray|sort_ci_by_key('age') %}
{% set myArray = myArray|sort_ci_by_key('age', 'desc') %}

View details

split

Splits a string into an array by the passed delimiter.

{% set data = 'one,two,three'|split(',') %}

View details

state_abbreviation

Gets the 2 letter state/province abbreviation for the variable value if the variable value is a valid state/province or state/province abbreviation.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|state_abbreviation }}

View details

state_data

Gets an array of state/province data for the variable value if the variable value is a valid state/province or state/province abbreviation.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set data = variable|state_data %}

View details

state_name

Gets the full state/province name for the variable value if the variable value is a valid state/province or state/province abbreviation.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ variable|state_name }}

View details

striptags

Strips HTML tags from the string.

{{ post.abstract|striptags }}

View details

text2html

Converts a plain-text string to HTML characters. Newline characters are converted to <br> tags. URL are also converted to links.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ post.plainDescription|text2html }}

View details

theme_url

Prepends the URL of the theme asset with the theme path. This is useful when using images, CSS or Javascript theme assets in the theme templates. It ensure that if the path to the theme changes then the links to the theme assets won't be broken.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
<link rel="stylesheet" href="{{ 'css/index.css'|theme_url }}">

View details

time

Formats a timestamp to a given time format.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ post.publishedOnTimestamp|time('H:i A') }}

View details

time_ago

Formats a date as human readable time difference from now (e.g. 2 minutes ago, 5 hours ago or 6 days ago).

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ post.createdOnTimestamp|time_ago }}

View details

title

Converts a string to have the first letter of each word capitalized and all other characters lower case.

{{ post.postTitle|title }}

View details

trim

Strips whitespace (or other characters) from the beginning and end of a string.

{{ ' BranchCMS is awesome! '|trim }}

View details

truncate

Shortens a string to the specified length. This does not take HTML tags into consideration.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ var|truncate(20) }}

View details

truncate_html

Shortens a string to a specified length and ensures that the HTML does not get broken.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ post.content|truncate_html(100) }}

View details

ucfirst

Capitalizes the first character of a string and leaves all other characters alone.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ post.postTitle|ucfirst }}

View details

ucwords

Capitalizes the first character of each work and leaves all other characters alone.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ product.productName|ucwords }}

View details

unique

Gets the unique values from an array.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set unique = arrayVariable|unique %}

View details

upper

Converts a string so that all characters are uppercase. 

{{ post.postTitle|upper }}

View details

url

Makes sure that the URL path starts and ends with a slash if necessary and is a proper URL.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ profile.website|url }}

View details

url_domain

Parses the URL and returns just the domain value.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ 'https://www.branchcms.com'|url_domain }}

View details

url_encode

Encodes a string to be part of a URL. Or, it converts an array to be a query string.

{{ variable|url_encode }}

{{ {'param': 'value', 'foo': 'bar'}|url_encode }}

View details

url_host

Parses the URL and returns just the host value.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ 'https://www.branchcms.com'|url_host }}

View details

url_suffix

Parses the URL and returns just the domain name suffix (i.e. the top-level domain and second-level domain if it exists).

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ myUrl|url_suffix }}

View details

values

Gets just the values of an array without any specific keys.

This filter is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set array = {'foo': 'Foo', 'bar': 'Bar'} %}
{% set values = array|values %}

View details

This documentation is only for Aptuitiv CMS. Learn more.
Get Started With Aptuitiv