ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 383 forks source link

Use extname setting for template paths in instance methods #104

Open ricardograca opened 9 years ago

ricardograca commented 9 years ago

I'm not sure if this is possible, but it would save some typing (and possibly refactoring time in the future) if express-handlebars instance methods used the extname setting to figure out the path of the specified template. Right now it seems to be required to pass the full path (relative to the project's root) to the express-handlebars instance methods (for example: getTemplate, render):

hbs.render('views/some/stuff.handlebars`).then(function(renderedTemplate) {
  /* ... */
})

However, by setting extname when creating the instance, I expected that instance to know what kind of extension I'm using for templates, so I could do just this:

hbs = exphbs.create({extname: '.handlebars'})
hbs.render('views/some/stuff`).then(function(renderedTemplate) {
  /* ... */
})

That would just leave the issue of figuring out automatically where the views are located, but that is probably more complicated right?

ericf commented 9 years ago

Since most of the time templates are rendered via Express there's no need to do this since Express' View module will figure out which extension to add if it's missing. If you'd like to add this because you're calling render() on the Express Handlebars instance, feel free to open a PR for it; you could look into how Express does this for the implementation details.

ricardograca commented 9 years ago

Great! I'll take a look into in when I have some free time. So, just to clarify, it won't break anything if this functionality is included in the Express Handlebars' render method right?

ericf commented 9 years ago

Correct, it should be possible to add this feature without breaking back-compat.

ericf commented 9 years ago

@ricardograca I've done a refactor of this package and plan to release v2.0 soon which adds support for the newly released Handlebars 3.0. If you're still interested in making this change, checkout #105 and make it against the handlebars-3.0 branch.

ricardograca commented 9 years ago

Thanks. Will do.