Twig Functions

attribute

Used to access a "dynamic" attribute of a variable. It's useful if the attribute has punctuation in it like a dash as that can cause issues with using the . notation of getting attributes.

{{ attribute(array, key) }}

View details

clone

The clone function allows you to clone an object. It's typically used to clone HTML objects like an image object.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set newImage = clone(someImageObject) %}

View details

compare_modified_date

Allows you compare the modified on date for the page with the "If-Modified-Since" header in the request to see if a "304 Not Modified" http status code should be returned. If the "If-Modified-Since" date sent from the browser in the request is the same as the "last modified" date of the page then a 304 http status code is automatically set, no content is returned and the response is sent. 

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{% do compare_modified_date() %}

View details

create_image_object

The create_image_object function allows you to create an image object from either an image URL/path or an array of image attributes.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set newImageObj = create_image_object('images/max-lissenden-tJxu4j4-T4o-unsplash.jpg') %}

View details

cycle

Cycles through an array of values. Useful for alternating values within a loop.

{% for item in items %}
    <p class="{{ cycle(['odd', 'even'], loop.index0) }}">{{ item.itemName }}</p>
{% endfor %}

View details

dump

Outputs the contents of a variable for debugging. The data is formatted and styled in an Aptuitiv HTML element. If not variable is passed then all variables in the current context will be outputted.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{# Output one variable #}
{{ debug(variable) }}

{# Output multiple variables #}
{{ debug(variable, anotherVar, yetAnotherVar) }}

{# Output all variables #}
{{ debug() }}

View details

Allows you to set an HTTP header for the response. 

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{% do header('Pragma', 'cache') %}

View details

http_response_code

Sets an HTTP response status code.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{% do http_response_code(404) %}

View details

parse_url

Parses a URL and returns either an array of the different URL parts or a single value if a specific URL part is specified.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set url = parse_url(item.website) %}

View details

path_info

Parses a file path and returns either an array of the different file path parts or a single value if a specific file path part is specified.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{% set fileParts = path_info(item.image.value) %}

View details

random

Returns a random value depending on the supplied parameter type.

{{ random(['bike', 'train', 'car']) }}
{{ random('ZYX') }}
{{ random() }}
{{ random(5) }}

View details

random_letters

Returns a random string of letters for the specified length. The letters could be uppercase and lowercase.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ random_letters(10) }}
{# Outputs a random string of letters 10 characters long #}

View details

random_number

Returns a random string of numbers for the specified length.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ random_number(4) }}
{# Outputs a random number 4 characters long #}

View details

random_string

Returns a random string of letters and/or numbers for the specified length. The letters could be uppercase and lowercase.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{{ random_string(6) }}
{# Outputs a random string of letters and/or numbers 6 characters long #}

View details

range

Returns an array containing an arithmetic progression of integers.

{% for i in range(0, 3) %}
    {{ i }},
{% endfor %}

View details

redirect

Allows you to redirect to another URL.

This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{% do redirect('http://www.branchcms.com') %}

View details

set_api_attribute_value

Only used when setting values for an API attribute such as

  • Multi-Select Box using data from an App API call
  • Multiple Checkboxes using data from an App API call
  • Select Menu using data from an App API call
This function is unique to Aptuitiv. It is not part of the core Twig functionality.
{% for post in posts %}
    {% do set_api_attribute_value(post.id, post.postTitle) %}
{% endfor %}

View details

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