Templates
In the Extra Horizon cloud, you can create mail templates which the mail service can use to send well-formed emails. You can manage these templates with the Extra Horizon client as well.
Listing templates
List the id, name and the description of all templates:
To get more information than the three properties listed use the get
command on a single template.
Get a single template
To get the full template by name
Or by id
Arguments
--name
This argument is used to specify the name of the template to retrieve
--id
This argument is used to specify the id of the template to retrieve
Synchronizing templates
If you want to create a new template, you need to create a json file which defines how it should look like.
Building on that functionality, the CLI offers additional functionality to more easily manage templates and allowing templates to build upon other templates. Once you've built these templates, you can use exh templates sync [options]
to synchronise these templates to the cloud.
Arguments
--template
This argument is used to specify the path to the JSON file or the directory that contains the single template to be synced.
--path
This argument is used to specify the directory that contains all the template files to be synced.
Creating templates
Templates can be a single json file but in the case where you have multiple pieces of content you can also split the template up into multiple file and put those files in a folder. For example if you have an html file which you want to include in the template: it's easier to maintain if you put the html file separate instead of inlining it into a json file.
Single json file
This is the easiest case. Everything is contained in the json file. The CLI will use the name of the file (minus the extension) as the template name.
Folder
If you prefer to split things up, you can put everything into a single folder. The name of the folder will be the name of the resulting template. A folder should contain a template.json
. Any other file in the folder will be read as text and is added to the fields
property of the template.json
file.
Example:
password_reset_email/template.json
password_reset_email/body.txt
Run the CLI to create the template:
From those files, the CLI will build the following resulting template:
Extending templates
Once you've made a number of templates, you'll notice that there are a lot of common things between the different templates and you end up repeating the same thing. This makes management more cumbersome because a single change to those common things will affect multiple files and it's easy to make mistakes. Therefore the CLI supports extending of templates, which means that we can start to build hierarchies of templates.
Templates like, for example, base_mail
and base_button_mail
could be extended by other templates.
You can extend from a template by adding an extends_template
-property to your template.
Extending a template will search for $content.___
variables in the extendable template its fields and will replace them with the extending templates fields with the same name.
Example
A simplified template to extend from: (containing a first_name
and message
reference)
basic_template.json
A template extending the above template: (passing along its own input name
to first_name
and filling the message
reference)
registration_message.json
Will result in the following template:
Note
The templates from which you extend, do not necessarily need to be in your folder. If the CLI didn't find the template in the specified sync folder, it will query the Extra Horizon cloud. If the template cannot be found there either, an error will be thrown.
The
sync
command will either create or update a template (if the name already exists). It will never delete a template.
Deleting templates
Any template can be deleted by using the delete
command
Or by id
Arguments
--name
This argument is used to specify the name of the template to delete.
--id
This argument is used to specify the id of the template to delete.
Last updated