Custom Objects Support
Use data from Mautic Custom Objects in your Twig Templates.
This feature needs the MauticCustomObjectsBundle plugin. Make sure it’s installed and active in Mautic.
You can show information from your Mautic Custom Objects (like orders, subscriptions, etc.) directly in your emails or landing pages using Twig Templates.
Getting Custom Object Data
Use the getCustomObjectItems
function to fetch data from a specific Custom Object.
getCustomObjectItems(alias, limit, page, orderBy, orderDirection, search, contactId)
What the options mean:
alias
(Required): The unique name (alias) of your Custom Object (e.g.,'orders'
).limit
: How many items to get (default is 1000).page
: Which page of results to get (for pagination, default is 1).orderBy
: How to sort the items ('id'
or'name'
, default is'id'
).orderDirection
: Sort direction ('ASC'
for A-Z,'DESC'
for Z-A, default is'ASC'
).search
: Text to search for within the items (optional).contactId
: Get items linked only to a specific contact ID. Usecontact.id
for the current contact (optional).
What you get back:
The function gives you a list (array) of items. Each item contains:
id
: The item’s ID.name
: The item’s name.fields
: A collection of all the custom field values for that item. You access them using their alias (e.g.,item.fields.your_field_alias
).
Using the Data
After fetching the items (e.g., {% set myItems = getCustomObjectItems('orders') %}
), you can loop through them and show their details:
Example: Show Recent Changelog Entries
Fetch the 5 newest items from a ‘changelogs’ Custom Object.
Example: Show the Current Contact’s Last Order
Fetch the single latest order from an ‘orders’ Custom Object linked to the current contact.