Skip to content
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

Non basic template pathing? #320

Closed
marcwhitbread opened this issue Aug 29, 2018 · 9 comments
Closed

Non basic template pathing? #320

marcwhitbread opened this issue Aug 29, 2018 · 9 comments
Labels

Comments

@marcwhitbread
Copy link

Can I do something like template: 'content/some_key'? or '../content/some_key'?

@niftylettuce
Copy link
Collaborator

I'm not sure what you mean - can you be more elaborate with a code example? We do expose the send and render methods.

@marcwhitbread
Copy link
Author

marcwhitbread commented Aug 29, 2018

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?

@niftylettuce
Copy link
Collaborator

If you look in the codebase, the render method uses a function getTemplatePath. You would either need to do one of two things:

  1. Pass a custom render function (see https://github.com/niftylettuce/email-templates#custom-rendering-eg-from-a-mongodb-database)
  2. 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 using this.getTemplatePath it would simply set filePath to the value /absolute/path if the Boolean value was true for isAbsolutePath (e.g. in email.render(template, locals, isAbsolutePath = false).

@marcwhitbread
Copy link
Author

Awesome dude! I'll take a look and possibly go the PR route 👍

Thanks for the quick reply!

@niftylettuce
Copy link
Collaborator

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 😄

@niftylettuce
Copy link
Collaborator

Going to re-open this- once we resolve/patch/PR we can close 😄!

@niftylettuce niftylettuce reopened this Aug 29, 2018
@niftylettuce
Copy link
Collaborator

@marcwhitbread would love a PR ❤️ !

@pke
Copy link
Contributor

pke commented Oct 4, 2018

@niftylettuce Would that solve the issue?
#329

@niftylettuce
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants