Email Templates
https://z.explo.org/documents/email_templates
Email templates are the way that Z handles the familiar "merge email" problem: needing to send the same email to a lot of recipients, with some information conditionally changing depending on details of any given recipient.
Making Your Own Template
The email template system in Z goes the extra mile and allows email templates to use the almost any Elixir
language construct to define logic in the email templates.
To make a template, start here. Type your template information into the relevant fields, and double-check in the "live preview" that things are looking like they should.
To reference variable data or perform calculations, you can use any Elixir syntax in your templates. You "wrap" the Elixir code in EEx
template tags, like so:
# in Elixir...
iex> 1 + 1
2
# in an HTML template...
<%= 1 + 1 %>
2
Example / Starter Templates
We've created some sample templates to help give a better idea of what's possible. Click each link below to be brought into an HTML template editor with the example pre-loaded:
- Example Email with variables, HTML, and conditional statements in the template.
Resources
We've put together some further reading that may prove helpful.
- See the html templates guide for more information about
Elixir
and HTML.
Z System
Here in Z, these are the modules that contain HTML template code and documentation.
Z.Documents
- Information about handling template dataZ.Documents.EmailTemplates
- "Business logic" for handling email template data and rendering email templatesZWeb.Documents.EmailTemplatesLive
- The "human" interface to email templates. This is where you see, edit, and preview templatesZSchemas.Documents.EmailTemplate
- The data definition of an email templateUtility.EExSafeEngine
- The place where we make sure nobody's trying to inject malicious code into our templates