forwardemail / email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for @forwardemail, @ladjs, @cabinjs, @spamscanner, and @breejs.
https://forwardemail.net/docs/send-emails-with-node-js-javascript
MIT License
3.64k stars 339 forks source link

[fix] Pug block extends doesn't work #444

Closed mikayelyan closed 1 year ago

mikayelyan commented 1 year ago

Describe the bug

Node.js version: v16.13.1

OS version: Ubuntu 20.04.5 LTS (Focal Fossa)

Description: Unable to reuse block code (layouts) when using pug engine.

Actual behavior

Result

Test Email

Expected behavior

Result

Test Email

hello world

Code to reproduce

const templatesPath = path.join(__dirname, '..', 'templates');

const email = new Email({
  message: {
    from: process.env.EMAIL_USER,
  },
  views: {
    root: templatesPath,
  },
  send: true,
  transport: transporter,
});
const sendEmail = async (template, recipients, data) => {
  const recipientList = IS_PRODUCTION
    ? recipients
    : getMockRecipients(recipients);

  try {
    const result = await email.send({
      template,
      message: { to: recipientList },
      locals: data,
    });
    log.info(result);
  } catch (err) {
    log.error(err);
    throw err;
  }
};

Templates file structure. app.js

html.pug

p Test Email

block content

hello.pug

extends html

block content
    p hello world

Checklist

mikayelyan commented 1 year ago

Actually, it works. Here I shouldn't use extends/block but just need to include the file we need. (or use mixins, which also works fine)

p Test Email

include hello.pug