-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Override compileTemplate #2
Comments
No, but there is nothing wrong with requiring express-handlebars and passing that instance into this plugin. What is the aversion with doing that? |
Could you please provide a snippet on how to do that? I am trying this ...
var nodemailer = require('nodemailer');
var sgTransport = require('nodemailer-sendgrid-transport');
var expHbs = require('express-handlebars');
var nodemailerExpHbs = require('nodemailer-express-handlebars');
var juice = require('juice');
var sgOptions = {
auth: {
api_user: process.env.SG_AUTH_API_USER,
api_key: process.env.SG_AUTH_API_KEY,
}
};
//Testing out instance vs factory
var exFactory = expHbs({ /* config */ });
var exInstance = expHbs.create({ /* config */ });
var compileTemplate = expHbs.compileTemplate.bind(expHbs); // <-- fails here
expHbs.compileTemplate = function (template, options, callback) {
// Pre-process template here.
compileTemplate(template, options, function (err, compiled) {
// Post-process template here.
callback(err, juice(compiled));
});
};
var viewEngineOptions = expHbs.create({
extname: '.hbs',
layoutsDir: 'server/views/email/',
defaultLayout: 'template',
partialsDir: 'server/views/email/partials/'
});
var nodemailerExpHbsOptions = {
viewEngine: viewEngineOptions,
viewPath: 'server/views/email/',
extName: '.hbs'
};
var mailer = nodemailer.createTransport(sgTransport(sgOptions));
mailer.use('compile', nodemailerExpHbs(nodemailerExpHbsOptions));
... but it fails miserably as .compileTemplate does not seem to be available... Sorry for posting a question here. |
Instead of supplying the options into the viewEngine add the actual express-handlebars instance like so
I'm not sure what's failing on this line
It's beyond the scope of this plugin. I'd check with express-handlebars maintainer. |
What fails is that |
This is really something you probably should bring up with the maintainer of that repository. It's beyond the scope of this plugin. Closing. |
True, thanks. |
Hi,
I am trying to override/use the
compileTemplate
of express-handlebars in order to inline all the CSS styles with juice (found the way here).I tried this:
but obviously I would need to require 'express-handlebars' and not 'nodemailer-express-handlebars'. But is there a way to do that without installing the extra package (as it is already included with this one)?
Thanks!
The text was updated successfully, but these errors were encountered: