PlusAuth uses Twig as its templating engine. This makes it possible to dynamically personalize emails and SMS messages based on user data, application information, or request context. For example, you can insert a user's name, check their locale, or adjust content depending on the client application.
To help you get started, we’ve prepared an Introductory Guide to Twig . It covers the basics of syntax, variables, filters, functions, and operators, so you can start customizing your templates right away.
Preview and Variables
When editing a template:
- Switch to the Preview tab to see how your template will look.
- Use the Edit preview variables button above the editor to adjust test data.
Preview variables are only for testing purposes. Changes made to the preview JSON do not affect real usage.
Available Variables
Each template may have a different set of variables. You can find the list of variables for each template in their preview variables from the dashboard. The following variables are available for every template:
Key | Description |
---|---|
request.language | Language parameter of request. See Localizing Templates |
application.name | Initiating Client's name |
application.id | Initiating Client's id |
application.metadata | Initiating Client's metadata |
tenant.id | Your tenant's id |
tenant.display_name | Your tenant's display name |
user | Target user object. See Reference |
Localizing Templates
The most straightforward way to localize your templates is by using the user.profile.locale
variable. This value is managed by your application. You must update the user.profile.locale
field through the PlusAuth REST API by calling Update User endpoint whenever a user's preferred language changes (for example, when they choose a language in your app settings).
Alternatively, you can use the request.language
variable. This variable represents the language code derived from the incoming request and is resolved as follows:
X-Request-Language
header – You can explicitly set this header to send a custom locale value.Accept-Language
header – This header is sent automatically by browsers to indicate the user's preferred languages.
If both headers are present, X-Request-Language
takes priority. This allows you to override the browser's default language when needed.
The following template snippet checks the user's locale, falling back to first locale defined at request.language
if not set:
{# Use the user's profile locale if available, otherwise take the first language from request.language #}{% set locale = user.profile.locale ? user.profile.locale : (request.language | split(";") | at(0)) %}
{% if 'de' in locale %} Verfügbar{% elseif 'tr' in locale %} Mevcut{% else %} Available{% endif %}