Closed theprobugmaker closed 5 years ago
@niftylettuce Why is this closed?
@zefexdeveloper i also what to know if thats possible.
basically i manage to "customized" the creation of content on this line: https://github.com/niftylettuce/email-templates/blob/master/src/index.js#L152
ive override the the function, what i mean is that from there maybe we can use all handlebars can do.
Ive never tried working on these idea yet.
Specify the partials
option in your configuration.
const Email = require('email-templates');
const email = new Email({
message: {
from: 'niftylettuce@gmail.com'
},
transport: {
jsonTransport: true
},
views: {
options: {
extension: 'hbs',
partials: {
myPartial: 'partials/myPartial'
}
}
}
});
Source: https://github.com/tj/consolidate.js/blob/master/lib/consolidate.js#L872-L874
If this works please submit PR to this repo's README with an example. Thank you.
seems that approach is not working anymore,
i tried this definition
new EmailTemplate({
htmlToText: false,
views: {
root: path.resolve('emailing/views'),
options: {
extension: 'hbs',
partials: {
samplePartial: '---just-a-simple-text----',
}
},
},
});
i got this error
UnhandledPromiseRejectionWarning: Error: The partial samplePartial could not be found
at Object.invokePartial (/home/meegle/tools/node_modules/handlebars/dist/cjs/handlebars/runtime.js:281:11)
at Object.invokePartialWrapper [as invokePartial] (/home/meegle/tools/node_modules/handlebars/dist/cjs/handlebars/runtime.js:68:39)
at Object.eval [as main] (eval at createFunctionContext (/home/meegle/tools/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:257:23), <anonymous>:8:28)
it seems it cant detect the partial being registered, im following this example here
https://handlebarsjs.com/partials.html
Round 2 I found another way to inject the partials, as i read some insights here: https://documentup.com/niftylettuce/node-email-templates
Example:
// override the engine first
handlebars.registerPartial('samplePartial', 'this is partial')
module.exports = new EmailTemplate({
htmlToText: false,
views: {
root: path.resolve('emailing/views'),
options: {
extension: 'hbs',
},
},
});
and this works for me
Yeah after debugging i see that partials doesn't pass to handlebars engine at all
"email-templates": "^8.0.2",
I was wondering if it's possible to set handlebars partials? I feel like I'm repeating myself a lot in the email templates, something that I could easily get rid of using partials by just including it.
Thank you