Answer the question
In order to leave comments, you need to log in
How to pass a piece of html layout to handlebars?
I need to generate an html layout for a table and pass it to the template, but as a result, the layout is inserted as text.
const fs = require('fs');
const path = require('path');
const nodemailer = require('nodemailer');
const hbs = require('handlebars');
// ... class mail ...
(async () => {
const mail = new Mail();
const source = fs.readFileSync(
path.join(__dirname, '/layouts/order.hbs'),
'utf8'
);
const template = hbs.compile(source);
await mail.sendMail({
to: '[email protected]',
subject: 'Заказ',
html: template({ products: '<h1>Test Html</h1>' }),
});
})();
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
</style>
</head>
<body>
<table>
<caption>
Товары
</caption>
<tr>
<th>Наименование</th>
<th>Кол-во</th>
<th>Цена, руб.</th>
<th>Скидка</th>
<th>Итог</th>
</tr>
{{products}}
</table>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question