Plugin for design and manage liquidjs email templates in Strapi.
The Strapi Liquid Templates Plugin is a custom plugin for Strapi which allows to design and manage your liquidjs email templates.
To install the The Strapi Liquid Templates Plugin, simply run one of the following command:
npm install strapi-liquid-templates
yarn add strapi-liquid-templates
Type | Description |
---|---|
Base Template | Layout templates which can be used with your custom templates or core templates |
Custom Template | Email templates which can be used with emails |
Core Template | Predefined email templates by users permissions plugin of strapi |
Base Templates are the layout templates which can be used with your custom templates or core templates.
After installation, click on Liquid Email Templates
at the dashboard sidebar menu.
Click on New Template
button, and fill the required details for your base template.
Press on Save
to save your base template.
Click on Custom Templates
from the Template Types.
Click on New Template
button, and fill the required details for your custom template. You can use your base template as the layout by selecting it from the dropdown menu.
You can preview your template in desktop and mobile views by clicking on the Expand icon in the Preview section.
Once you're done with it, press on Save
to save your custom template.
There are two core templates available for customization.
- Email address confirmation
- Reset password
Click on Core Templates
from the Template Types.
Click the template you want to edit, and fill the required details for your core template. You can use your base template as the layout by selecting it from the dropdown menu.
Once you're done with it, press on Save
to save your core template.
Request a password reset for a user which was created under User collection type.
You can send emails programmatically by using the Strapi Liquid Templates
plugin. Here is an example of how to send an email:
// import type { Core } from '@strapi/strapi';
export default {
/**
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
*/
register(/* { strapi }: { strapi: Core.Strapi } */) {},
/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*/
async bootstrap(/* { strapi }: { strapi: Core.Strapi } */) {
try {
await strapi
.plugin('liquid-templates')
.service('email')
.sendLiquidEmail(
{
// required
// This can also be an array of email addresses
to: 'to@example.com',
// Optional
cc: ['cc-one@example.com', 'cc-two@example.com'],
// Optional
bcc: ['bcc@example.com'],
// optional if /config/plugins.js -> email.settings.defaultFrom is set
from: 'from@example.com',
// optional if /config/plugins.js -> email.settings.defaultReplyTo is set
replyTo: 'reply@example.com',
// optional array of files
attachments: [],
},
{
// required - Reference Id defined in the custom template (won't change on import)
referenceId: 'account-approved',
// If provided here will override the template's subject.
// Variables can be included as `Congratulations {{ USER.firstName }}! Your Account has been approved!`
subject: `Account Approved`,
},
{
// this object must include all variables you're using in your email template
USER: { firstName: 'John', lastName: 'Doe' },
}
);
strapi.log.info('Email sent');
} catch (error) {
strapi.log.error(error);
}
},
};
If you want to say Thank You and/or support the active development of Strapi Liquid Email Templates
:
- Add a GitHub Star to the project.
- Support the project by donating a cup of coffee.
This plugin is licensed under the MIT License. See the LICENSE file for more information.