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

Each partials dir can be namespaced. #64

Closed joanniclaborde closed 10 years ago

joanniclaborde commented 10 years ago

As stated in #20, having multiple partialsDir can introduce naming collisions. This pull request adds support for partials namespaces. Each partialsDir can optionally be specified as an object, with a dir and namespace properties. Example:

var partialsDir = [
  'local/views',
  {dir: '/otherPackage/shared/views', namespace: 'otherPackage'}
];
...
app.engine('handlebars', exphbs({partialsDir: partialsDir}));

If both local/views and /otherPackage/shared/views contain a template named status.hbs, they can be included like this in a view:

{{> status}}
{{> otherPackage/status}}
ericf commented 10 years ago

@joanniclaborde thanks! This seems like a reasonable request. I might try to make this automatic by adding some logic to the _getPartialName() method, instead of forcing it via config.

ericf commented 10 years ago

@joanniclaborde I've recently rewrote this package to use Promises. As stated above, I think this is a good feature to add for v1.0. Would you be up for re-implementing this PR against the promises branch? If not, I can re-write these changes to work with the new branch; just wanted to make sure you had a chance to get commit-credit for it.

joanniclaborde commented 10 years ago

Sure, I'll try to get this done within the next few days!

ericf commented 10 years ago

@joanniclaborde thanks! Sorry for the churn.

joanniclaborde commented 10 years ago

Done, it's here: https://github.com/ericf/express3-handlebars/pull/70

It's the first time I try Promises, but I think all is working fine...

ericf commented 10 years ago

Closing in favor of #70