Available Twig Tokens
Reference guide for tokens available within the Twig Templates plugin for Mautic.
The Twig Templates plugin provides several objects and tokens you can use to access Mautic data and perform actions within your templates.
Contact Object (contact
)
The contact
object provides access to the fields of the contact viewing the email or landing page.
- Standard Fields: Access any standard Mautic contact field using its alias (e.g.,
contact.firstname
,contact.email
,contact.city
). - Custom Fields: Access custom contact fields using their alias (e.g.,
contact.custom_field_alias
). - Tags: Access the contact’s tags as an array.
- Segments: Access the segments (lists) the contact belongs to as an array of objects. Each object has properties like
id
andname
. - Companies (
contact.companies
): Access all companies associated with the contact as an array of company objects. Each object contains the company’s fields. - Primary Company Shortcut (
contact.primaryCompany
): Returns the primary company object if one is set. If no company is explicitly marked as primary, it returns the first company associated with the contact. Returnsnull
if the contact has no associated companies.
Form Result Tokens
You can access form submission data in your Twig templates using special variables and a new function:
-
formresult
: An object containing the data from the most recent form submission by the contact for the form that triggered the current action. Field names correspond to form field aliases.Important: This only works if the email is sent using:
• A “Send email to contact” action directly on a form.
• A “Send email” action in a campaign that starts when a form is submitted. -
formresults
: An array containing all form submission data for the triggering form and contact. Each element is an object likeformresult
.Important: This only works if the email is sent using:
• A “Send email to contact” action directly on a form.
• A “Send email” action in a campaign that starts when a form is submitted. -
getFormResults(formId, contactId, limit, page, orderBy, orderDirection)
:
A Twig function to fetch form submission results for any form by its ID, with optional filters and pagination.formId
(required): The ID of the form.contactId
(optional): The contact’s ID. If omitted ornull
, fetches results for all contacts.limit
(optional): Max number of results per page.page
(optional): Page number (default: 1).orderBy
(optional): Field to sort by (default:'s.date_submitted'
).orderDirection
(optional):'ASC'
or'DESC'
(default:'DESC'
).
-
getFormResultsCount(formId, contactId)
:
A Twig function that fetches the total count of form submissions for a specific form ID.formId
: (Required) The integer ID of the Mautic Form you want to query.contactId
: (Optional) The integer ID of the Mautic Contact. If provided, counts submissions for that specific contact only. If omitted ornull
, counts submissions for the form across all contacts.- Returns an integer representing the total number of matching submissions.
- Available in Emails, SMS, and Landing Pages.
- Example (Show how many times the current contact submitted Form 12):
- Example (Show the total number of submissions for Form 12 across all contacts):
Examples:
See Forms Support for more details and examples.
Email Tokens (tokens
)
When sending emails via the API, you can pass custom tokens in the payload. These are accessible via the tokens
object. See the API Documentation for usage.
This list covers tokens specifically added or enhanced by the Twig Templates plugin. Standard Twig variables and functions (like now
for the current time) are also available. Refer to the official Twig Documentation for more on standard Twig capabilities. For accessing Custom Objects data, see the Custom Objects Support page.