Mustache for Dynamic Content
Use Mustache to inject dynamic content into your Enveloop messages.
Last updated
Was this helpful?
Use Mustache to inject dynamic content into your Enveloop messages.
Last updated
Was this helpful?
Enveloop supports in our messaging platform -- you will use this whenever you use variables or dynamic content in your messages. Also, this is a good way to inject some basic logic. Below are a few examples:
Here's a simple message that notifies a user about updated contact information.
Here is the same message, but updated to include variables using Mustache. These variables can be received via an API call and tested inside the Enveloop app.
When you add these to your message, Enveloop auto-detects the variables and provides input areas for testing content in the Test view of the message.
When a variable exists ...
Sometimes it makes sense to have multiple templates in Enveloop. However, if you have a couple of conditional changes, using Mustache, you can block out content in a single template, and the content will only be displayed if a variable exists.
In the below example, a user receives an invite to a project. If the user doesn't have an account already, we want to provide some additional instructional text. If our variable new_user
exists or is true
, then the content in the block will be displayed in the email.
Note: If the new_user
variable does not exist or is false
, the content will not be displayed.
When a variable does not exist ...
You can provide content conditional on a variable not existing as well. You'll need to change the prefix symbol on the variable. Instead of using a #
(pound/octothorp), you will use a ^
(caret), and the text within the block will be displayed, assuming the variable has not been provided in your API call.
You'll still terminate the tag using the same backslash.
In Enveloop, you can send a JSON object via a variable in an API call.
You can use a Mustache Section to render the object(s), Sections render blocks of text one or more times, depending on the value of the key in the current context.
A section begins with a pound and ends with a slash. That is, {{#person}}
begins a "person" section while {{/person}}
ends it.
Also, you can use a single dot/period to output an object.
In this example, we want to create an unordered list of tags. If there are no tags present, we want to skip the list and simply say "No tags assigned yet."
This also works with nested sections like with a more complex example of an invoice item:
It's important to note that the object passed with the API call to Enveloop must be in a valid JSON format.
You can iterate over an array of objects in Mustache as well, using the {{#.}}
notation.
Looking to do more with Mustache? Awesome. Here's a . It outlines additional functionality you can use. We'd love to hear more about how you are using this!