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.

Snippet Setup

You can insert a variable into the snippet that will be pulled from the 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: support@sendwithus.com

Share this post
Tweet about this on TwitterShare on Facebook

One response to “How to use template-specific Jinja variables with Snippets”

  1. Mike says:

    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 *