Merge Tags
Merge Tags allow end-users to dynamically insert personalized content into their emails. These placeholders are replaced with real values when the email is sent, making it easy to create highly personalized and dynamic emails. Merge tags can be inserted into a block of text by clicking the "Merge Tags" button in the text editor toolbar.
If no merge tags are provided during initialization, the "Merge Tags" button will not appear.
How Merge Tags Work
Merge tags are placeholders that are replaced by real data at the time of sending the email. For example, the merge tag {{first_name}} might be replaced with "John" when an email is sent to a recipient.
Unlayer supports all templating engines, whether they use curly brackets {{ ... }}, square brackets [ ... ], or any other syntax.

Initializing Merge Tags
To pass merge tags to the builder, use the mergeTags configuration during initialization. Each merge tag requires a name (what the user sees), a value (the actual merge tag in the templating engine), and a sample value for preview purposes.
Example: Passing Merge Tags
unlayer.init({
mergeTags: {
first_name: {
name: 'First Name',
value: '{{first_name}}',
sample: 'John',
},
last_name: {
name: 'Last Name',
value: '{{last_name}}',
sample: 'Doe',
},
},
});
In this example:
- first_name will be displayed as "John" in preview mode.
- last_name will be displayed as "Doe" in preview mode.
Grouping Merge Tags into Sub-Menus
You can group related merge tags into sub-menus for better organization. This is useful for scenarios like grouping address fields under a "Shipping Address" menu.
Example: Grouping Merge Tags
unlayer.init({
mergeTags: {
shipping_address: {
name: 'Shipping Address',
mergeTags: {
street_1: {
name: 'Street 1',
value: '{{shipping_address.address_1}}',
},
street_2: {
name: 'Street 2',
value: '{{shipping_address.address_2}}',
},
city: {
name: 'City',
value: '{{shipping_address.city}}',
},
state: {
name: 'State',
value: '{{shipping_address.state}}',
},
zip: {
name: 'Zip',
value: '{{shipping_address.zip}}',
},
},
},
},
});
In this example, the user will see a "Shipping Address" sub-menu with Street 1, Street 2, City, State, and Zip options.