# Templates
Treezor uses the Twig 3.x templating engine (opens new window).
Like other files, templates should be base64 encoded.
# Twig Basics
A template is a file that contains both structure (sometime also styling) and instructions to inject content within. Such as: "display this variable or something else if the variable is unavailable", "iterate on this array", etc.
Information – Treezor implementation of Twig has the following limitations
- Layouts and Blocks are unavailable
- Variables are limited to those Treezor provide
- CSS styling must be inlined (
<a style="color:orange;">my link</a>
or within a<style type="text/css"></style>
in the page's<head>
)
# Emails templates
Your Email templates must produce HTML, an additionnal template producing TXT is also required. This TXT atlternative is dedicated to clients that don't support HTML such as screen readers for the visually impaired.
# Example
Reading – More information on how to format templates
# Checking supported endpoints
Not all Treezor endpoints support templates. To check out which endpoints can be templated, you can use the following request.
Returns the complete list of customizable templates.
# Listing available variables
To retrieve the list of variables available within a template, you can use the following request.
Returns the details about the template, including a list of accessible variables (variables
).
If you attempt to use an non-existent variable, an error is returned.
# Uploading a template
All templates must be uploaded to the following endpoint PUT {baseUrl}/customization/templates/{templateName}/template
, where the endpointName
URL parameter corresponds to the endpoint to which you want to apply this template.
Your base64 encoded template should not contain line break (\n
)
# Example
Caution – Replacing a Template
- Takes effect immediately.
- Cannot be undone.
# Testing a template
To test a template with dummy values, you can use the following request.
Returns an object containing a populated version of your template in the template
attribute.
# Accessing a template
To retrieve a template that you have already uploaded, you can use the following request
Returns an object containing your template in the template
attribute.
# Deleting a template
If you want to remove a template altogether, you can use the following request. The endpoint will immediately revert the indicated template to Treezor's default template.
# Using a template
To enable your template in a response, add the following header X-TrzConnect-Custom-Template
with a value of 1
.
# Errors
If something goes wrong while uploading a template, you can expect an Error object. Its message
attribute will contain useful debugging details.