Non basic template pathing?
marcwhitbread opened this issue · comments
Can I do something like template: 'content/some_key'? or '../content/some_key'?
I'm not sure what you mean - can you be more elaborate with a code example? We do expose the send
and render
methods.
Something like...
.send({
template: 'some/path/to/mars',
message: {
to: 'elon@spacex.com'
},
locals: {
name: 'Elon'
}
})
OR
.send({
template: '../../some/path/to/mars',
message: {
to: 'elon@spacex.com'
},
locals: {
name: 'Elon'
}
})
How does it work?
If you look in the codebase, the render
method uses a function getTemplatePath
. You would either need to do one of two things:
- Pass a custom render function (see https://github.com/niftylettuce/email-templates#custom-rendering-eg-from-a-mongodb-database)
- Fork this repo and submit a pull request that would allow a third argument to be passed to render, which could be a Boolean. As such you'd pass
email.render('/absolute/path', locals, true)
and instead of usingthis.getTemplatePath
it would simply setfilePath
to the value/absolute/path
if the Boolean value wastrue
forisAbsolutePath
(e.g. inemail.render(template, locals, isAbsolutePath = false)
.
Awesome dude! I'll take a look and possibly go the PR route 👍
Thanks for the quick reply!
Actually @marcwhitbread - you might not even need a third argument!
https://nodejs.org/api/path.html#path_path_isabsolute_path
You could just use that inside the render
method, and if it was an absolute path then it would not attempt to lookup the template 😄
Going to re-open this- once we resolve/patch/PR we can close 😄!
@marcwhitbread would love a PR ❤️ !
@niftylettuce Would that solve the issue?
#329
thanks @pke, I've released v5.0.1 of email-templates which includes this PR
update docs are available too at https://github.com/niftylettuce/email-templates#absolute-path-to-templates
cc @marcwhitbread care to try it out?