Template microservice. Generate html (email compatible) and pdf from the given template and data.
- fill html templates with data
- convert html css to inline css for emails
- pdf creation form template with data (get buffer / stream)
- Send email with template.
- In /src/templates/template create a new forlder with {templateName}
- Add a {templateName}.handlebars file (template)
- Your html <style> will be replaced with inline css because this is the only way it will work with emails
- Add a Validator class to {templateName} folder (extend TemplateValidatorAbstract - implement the validate(data: YourTemplateData) and exampleData(): YourTemplateData)
- Add the validator to TemplateFactory validators[]
- Done. You can see the generated links in the GET /template root, You can get the template as: html string, pdf buffer, pdf stream. Experiment and test with the playground link.
{{type}} = html_string | pdf_buffer | pdf_stream
POST /template/:name?type=html_string
body: templateData
POST /mail
body: {
mailOptions: Omit<Mail.Options, 'html'>;
template: { name: string; data: any };
}
//example body
{
"mailOptions": {
"to": "test@gmail.com",
"subject": "test email"
},
"template": {
"name": "test_template",
"data": {
"title": "test title",
"description": "This is a test description",
"color": "#DEB887"
}
}
}