How to use template-specific Jinja variables with Snippets
Recently, we received a question from a customer that prompted us to scratch our heads for a few seconds: “How can I use template-specific variables that aren’t passed into the data field of the API to send mail?” We did some research and devised a pretty simple and interesting solution.
The idea is to set up a Snippet which includes a variable of your choosing. Then you can set that Jinja variable separately in each template.
Once you have your variable in the snippet, all you have to do is set it in the template, like so:
In doing this you’ll be able to have the contents of the snippet render in the template using the previously set Jinja variable. There are tons of really cool possibilities for taking advantage of this method like building tracking urls and split testing your branding.
If you have any questions about how this works or you come up with another interesting use case, we’d love to hear from you: firstname.lastname@example.org