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.

Snippet Setup
You can insert a variable into the snippet that will be pulled from the template

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:

Set the Jinja variable
set variable, call snippet, profit

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:

Posted in News ProductTagged

One thought on “How to Use Template-specific Jinja Variables with Snippets

  1. Have been using this feature for a while and am loving it.

    We use it to have a default header style (i.e. a green ‘success’ header for a transactional mail) and then use the variable to pass in the relevant text to place in the header. That way, if we want to update our header styling later, all we need to change is the snippet.

    Fantastic! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *