To help provide a more cohesive experience for your user base, FastComments provides an email customization solution so that the emails sent to your customers, from FastComments, can match your branding.
In this documentation we will cover the features of this solution, the template language, localization, and more.
Creating Templates
The admin area for creating templates can be found by going to Customize -> Email Templates.
Here you will see a list of the different types of emails sent by the platform, with a description for each template describing when it is used.
For example, we can customize the Commenter Comment Notification
email, which is Sent when a commenter has a reply to their comment
.
Clicking Create Template
will not immediately apply changes. You may open the editor
for the default template and play around with the preview, and there will be no effect
until you hit Save
.
Template Language
FastComments Email Templates uses the EJS template language.
Example syntax is <%= object.someValue %>
to print variables, and conditional statements can be done as so:
<% if (some_condition) { %>
<div>Some content.</div>
<% } else { %>
<div>Some other content.</div>
<% } %>
Printing raw HTML, like for the comment content, is done like so: <%- comment.commentHTML %>
. Note the -
instead of the =
.
Refer to the above link for further documentation on syntax.
Localizing and Custom Text
FastComments is a localized platform. All of our widgets, emails, and notifications are localized.
Localized means that we show a different language, and formatting, based on the user's location and preferred language. We determine this based off the information the user's browser provides us.
We can customize the text in the email by going to the Translations
tab, selecting a Locale
and editing the text. Text that is changed from the default is outlined in the UI. You may
switch between locales and save at the end, without losing changes.
Localized text is accessed via the TEXT
object, for example: <%= TEXT.INTRO %>
.
SSO Note
For SSO integrations, if locale
is not specified, it will be updated every time the user
accesses the comment widget with a different locale. This means their language preference
is automatically updated, and future emails will be sent in that locale.
This can also be set manually by providing locale
in the SSO payload.
Per-Domain Templates
Templates can be setup to be global - across your entire tenant for that template type, or
per-domain. In the Settings
tab select the desired domain.
Note that if you set up multiple templates for the same domain, only the first is picked at runtime. The templates list will warn you when this situation occurs.
Data and Variables
Each template works within a different context, meaning different data is available.
A quick at-a-glance way to see what data is available is to check the test data
provided for the template. When editing a template, click the Test Data
tab to see
a JSON structure.
We can also customize the test data in this area, to see how our template looks
in different situations. The test data can be reset back to the default with the Reset
button.
Render Failures
Since email templates support variables, and logic, it is possible to create templates that fail to render, or sometimes fail to render.
This can be very frustrating to diagnose and debug, especially if it is an intermittent issue, or if it only occurs when the data looks a certain way.
To help, FastComments Email Templates has a couple features:
- If the template fails to preview, it cannot be saved. An error message will be shown.
- Template render failures are tracked and reported on in the admin UI.
The second bullet is describing render failures that happen in production. As in, you create a template which previews fine - but later fails for some reason. For example, if we have this in our template:
<% if (comment.commenterEmail.includes('test') { %>
This may fail sometimes if we have anonymous commenting enabled, since email will not always be available. So how do we find out about that?
The answer is that errors are surfaced in two places. First, the template list itself shows a render error count with each template.
Then, when viewing a template we can see a count, per-error, of the number times the template has failed to render.
A reset button is located next to each error, and its count, so that we can reset the counter after we have resolved an issue.