Templates allow you to create an email message entirely within Simon, with your HTML code and dynamic personalization defined in a single place.
Templates consist of HTML code combined with dynamic content in the form on _Jinja_ code. If you are already familiar with [Custom Context](🔗), the Jinja code in templates follows the same syntax and conventions. A key difference with templates is that all the dynamic content is defined within the template, so there is no need for separate Custom Context to be defined. You can still define metadata when you set up your flows.
# Accessing and using templates in simon
To get to templates, click on your email address to reveal the dropdown of options, and then select **Content**. On this page you can access any existing templates and create new ones.
The template editor lets you edit the HTML for your message, add dynamic personalization, preview the message for both a single contact and a batch of contacts, and perform a test send.
After you have completed setting up a template and saved your changes, you can use it in the flow builder by selecting the channel action **Send Email To Contact with Simon Templates**. Simply chose your template from the list, enter a subject, and complete the rest of the flow set-up. You will also have the option to preview the message and do a test send from within the flow builder. A template can be used in an unlimited number of flows.
Templates are only available with Simon Mail and SendGrid
While any user can create email templates, they can only be sent in Simon Mail and SendGrid journeys and flows.
# Creating and editing templates
The template editor consists of the code editor on the left-hand side, and the preview and personalization tabs on the right hand size.
## Code editor
The code editor highlights HTML syntax, and gives you the option to search, as well as collapse and expand HTML tags to navigate your code more easily.
The code editor also calls out possible syntax errors in your HTML templates. The alerts appear as red x's next to the line number in question. Hover over the x and you'll see the potential error details. These potential errors may or may not cause issues downstream so treat them as guidance. They don't prevent you from saving templates or from using those templates in flows.
## Message details
The message details can be found under the **@** icon. This allows you to save a default value for subject line, from name, from email address and reply-to email address. These values will be loaded as defaults when this template is selected in the flow builder, but you will also have the option to update them in the flow builder, such as for a subject line test. The subject line can contain personalization using contact properties in the form of Jinja expressions.
Updating message details after a flow is created
Once a flow has been set up, the message details are stored within the flow, and changes to message details made in the template will _not_ automatically update the flow. Any changes to the subject, from name, from email, or reply-to email must be made in the flow itself.
## Preview and sample contacts
The preview tab will show the message as rendered for a random contact in your database. As you change the code, the preview on the right hand side will automatically update. You can select a segment and sample contact for your template under Contacts. The contact that is selected there will be used for both the preview and test send. If you select a segment, the contact will be sampled from that segment. The segment will also be used to select the contacts for previewing a batch.
## Preview batch and test send
**Preview batch** allows you to preview a batch of 25 messages for randomly selected contacts in the selected segment. You can flip through the contacts to see how the content would look for each of them. **Test sends** will use the selected sample contact (with the ability to cycle through sample contacts) to populate the message personalization and will send the corresponding message to one or several email addresses. The test send will use the message details, if configured, and adds the text '[TEST]' before the subject. If message details have not been defined, the message will be sent as coming from your email address, with the template name as subject.
## Contact properties
Templates can incorporate contact properties for personalization, much the same as Custom Context. Clicking on a contact property will insert that value in the template. You can use contact properties both as conditional statements and to present them as content. **It is important that there is not a situation where there could be content missing from your message.** It is always recommended to set up a default value in the event of null customer or lookup table data. There is more information about how to use contact properties in [Custom Contexts - Explained](🔗).
Use validations and default values when inserting dynamic content
When working with any dynamic content it is important to ensure that content will not be missing from your message, e.g. if certain contacts are missing a property that you are using in your block. You can avoid this by adding checks for missing content and providing default values.
## Lookup tables
You can include content from lookup tables in your template just as you would for Custom Context. The Lookups tab lets you explore your lookup tables and clicking on a property will insert the code in the template. Just as with contact properties, it is important that you consider the situation of a missing property, in order to avoid missing or erroneous content. To find out more about how to use lookup tables, check out our tips about [Getting Started with Lookup Tables](🔗).
## Event data
Event data can be accessed under the **Events** tab if you have set up triggers using data from Simon Signal. In order to use event data within a template, you will first need to select the corresponding trigger. Make sure you use the same trigger as you intend to use in the flow. Once you've selected a trigger, you will be able to preview sample events for that trigger. You can sample different contacts to preview the content for different situations. (If a single contact has multiple events, you can move between those using the arrows).
You can learn more about how to use event data as content under [Using Event Data from Triggers](🔗).
Picking the right trigger
Because different triggers can have different data fields available, it is important to use the same trigger in the template builder and your flow. You should also confirm both in the template and flow builder that the content renders correctly.
Combining event data with contact properties
Certain triggers apply to contacts that do not already exist in the system, such as a registration event. When such a trigger is selected, contact properties will not be available in the template.
## Content blocks
Content blocks allow you to save static text or code and reuse it in multiple places without duplicating the information. When you want to make an update, you can do it in a single place. Find out more about blocks in [Content Blocks](🔗). Please note that it can take a couple of minutes for block updates to be refreshed in the templates preview.
# Using templates in the flow builder
Simon templates are available within the channel action **Send Email to Contact with Simon Templates**. After selecting your template, fill in your subject and the rest of the email details. The subject can include dynamic personalization using Jinja.
Because the personalization is already defined in the template, there is no option to add Custom Context, but there is a separate section to enter metadata. You will also find an option for test send.