Overview
If you need to create a variable that can be accessed within the template, you can use the assign statement.
{assign var=name value=$contact.first_name}
Alternate syntax
{$name = $contact.first_name}
{$name} may now be used throughout the message, and in this example, will render the first name of the contact.
When setting variables, refrain from using system reserved names such as "account", "message" or "contact", as they are reserved for displaying other variables in message content.
Use assigned variables as a link append
One common use case is using assigned variables to append links with query strings for 3rd party tracking. You can set a query string as a variable once in a message and have it populate all links in the message that use that variable.
For example, start by assigning the link append as a variable:
{assign var=link_append value="utm_source=example123&utm_campaign=example345"}
Then add the new variable to each of your links:
http://example.com?{$link_append}
When the message renders, all links using the assigned variable will be appended with the query string.
You can also combine this technique with contact attribute variables and Smarty modifiers for more control. Read the article on link appends for more detailed information.
In the next article, you can learn about external variables.
Comments
0 comments
Please sign in to leave a comment.