lookback / meteor-emails

Improved Meteor emails with templating, previews and automated CSS/SCSS inlining.

Home Page:https://atmospherejs.com/lookback/emails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could not preview email: Cannot read property 'preview' of undefined

imajus opened this issue · comments

Hi, I've just installed the package and I'm trying to create my first email. I have this email template in private/emails/test.html:

<header>
    <h1>Hello, World!</h1>
    <div class="alert alert-info">This is a test E-mail template.</div>
</header>
<div class="well">
    Donec rutrum congue leo eget malesuada. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec velit neque, auctor sit amet aliquam vel, ullamcorper sit amet ligula. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec velit neque, auctor sit amet aliquam vel, ullamcorper sit amet ligula. Nulla quis lorem ut libero malesuada feugiat. Cras ultricies ligula sed magna dictum porta. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Donec sollicitudin molestie malesuada. Donec rutrum congue leo eget malesuada.
</div>
<footer>
    //TODO
</footer>

This is template object in server/emails/test.js:

MailerTemplates = {};
MailerTemplates.test = {
    path: 'emails/test.html',
    route: {
        path: '/test',
    }   
}

This is my Mailer setup in server/mailer.js (replaced personal data with asterisks):

Mailer.config({
    from: 'noreply@********',
    routePrefix: 'emails',
    baseUrl: process.env.ROOT_URL,
    testEmail: '*********',
    silent: false,
    addRoutes: true,
    language: 'html',
    plainText: true,
    plainTextOpts: {}
});

Meteor.startup(function() {

    Mailer.init({
        templates: MailerTemplates,
        /*layout: {
            name: 'emailLayout',
            path: 'emails/layout.html',
        }*/
    });

});

So with this setup I can preview the email via /emails/preview/test which is great, but when I uncomment layout option for some reason I get Could not preview email: Cannot read property 'preview' of undefined mailer error both in a browser and in server console. No stack trace or anything that could help me to investigate the issue.

Can you assist me with that? What is the problem and how can I fix it?

Here's my private/emails/layout.html:

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <style type="text/css">
      {{{ css }}}
    </style>
  </head>
    <body>
        {{{ body }}}
    </body>
</html>

I've just figured out that by myself, I just needed to provide preview helper in Mailer.init object. Looks like a bug to me, missing preview helper should be handled properly.

Also, as a side note, you should definitely include {{{body}}} in your README layout example. So far it's unclear how to build layouts until I checked out an example source code.

Thanks @imajus. Great feedback. Glad you found it out, but I'll def update README + handle preview helpers. Keeping this open until that happens.

Ah I was wrong. Apparently the error occurs when I don't provide data property in template object. When I do provide data as a function simply returning an empty object everything goes well without any helpers.

+1

Templates["notification-client"] = {
  path: '/email-templates/notification-client.html',
  css: '/email-templates/stylesheets/general.css',
  route: {
    path: '/notification-client/',
  },
  helpers: {
    preview: 'Client Notification'
  } 
}