keystonejs / keystone-classic

Node.js CMS and web app framework
http://v4.keystonejs.com
MIT License
14.64k stars 2.21k forks source link

Does the KeystoneJS support custom view engine (like as swig) for Email Templates? #1275

Closed alexander-tsig closed 8 years ago

gilloud commented 9 years ago

Yes it's possible :

var view2 = new keystone.View(req, res); 
view2.render('mail', locals, function(err, html) { 
 locals.data.renderedMail = html; 
}); 

exemple : https://github.com/gilloud/AnnouncementManager/blob/master/routes/views/mail.js

railsjack commented 9 years ago

Wow, great. I will check it right now.

ttsirkia commented 9 years ago

In my opinion, that is a bit strange because you need req and res. I'm using Swig and noticed that this kind of code also works:

  keystone.get('custom engine')('templates/emails/register.swig', {name: 'John Example'}, function(err, result) {
    console.log(err, result);
  });

I'd like to know what is the most preferred way to do this and how to get rid of that custom engine part.

snowkeeper commented 9 years ago

Here are the defaults when calling the Email class

var defaultConfig = {
    templateExt: 'jade',
    templateEngine: require('jade'),
    templateBasePath: path.normalize(path.join(__dirname, '..', 'templates', 'helpers', 'emails')),
    mandrill: {
        track_opens: true,
        track_clicks: true,
        preserve_recipients: false,
        inline_css: true
    },
    // Mandrill template
    templateMandrillName: null,
    templateForceHtml: false // Force html render
};

Have you tried setting the template up when initiating the class. I have not tried another engine but this might work

var Email = new keystone.Email({
    templateName: 'template-name',
    templateExt: 'swig',
    templateEngine: require('swig'),
    templateBasePath: '/set-your-path'
});
VykintasZaboras commented 9 years ago

Hey, Doesn't seem to work with nunjucks. My options are:

templateName: 'confirm',
templateExt: 'html',
templateEngine: require('nunjucks'),
templateBasePath: '/templates/emails'

I get an error:

TypeError: object is not a function
    at null.<anonymous> (/node/project_name/node_modules/keystone/lib/email.js:218:46)

Any way to set the template engine and extension globally?

mxstbr commented 8 years ago

We're closing all questions and support requests to keep the issue tracker unpolluted. Please ask this question on Stackoverflow or Gitter instead!