@vladislav3101

Как в handlebars передать кусок html верстки?

Мне нужно сгенерировать html верстку для таблицы и передать в шаблон, но в результате верстка вставляется как текст.

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: 'admin@domain.com',
      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>
  • Вопрос задан
  • 153 просмотра
Решения вопроса 1
notiv-nt
@notiv-nt
Как ваше ничего? Да, моё тоже
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы