-
Notifications
You must be signed in to change notification settings - Fork 383
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
Inject more data to handlebars during render #101
Comments
Hmm… So I do have some Express Handlebars-specific metadata that could potentially be useful, and it contains the Also, if we do something like this, I think this metadata should be namespaced on the |
This upgrades to Handlebars 3.0 and makes backwards-incompatible changes to the ExpressHandlebars API. Since Handlebars had a major version bump, it seemed appropriate for this package to have a major version bump as well, so I took the liberty of refactoring some things. - Add `compilerOptions` config property which is passed along to `Handlebars.compile()` and `precompile()`. - Expose ExpressHandlebars metadata to the `data` channel during render (#101). This metadata is accessibile via `@data.ExpressHandlebars.*` - New "protected" hooks for AOP-ing template compilation and rendering, all of which can optionally return a Promise: - `_compileTemplate()` - `_precompileTemplate()` - `_renderTemplate()` For most apps this will be a drop-in replacement to v1 of this package, and using Handlebars 3.0 should be a drop-in replacement as well. That said, here's the changes that potentially break back-compat: - Removed using `prototype` props for default config values. - Removed `handlebarsVersion` from instances and `getHandlebarsSemver` static function on the `ExpressHandlebars` constructor. - Replaced undocumented `compileTemplate()` hook with the protected but supported `_compileTemplate()` and `_precompileTemplate()` hooks.
@dominicbarnes I've added support for this in #105. Here is what I'm currently exposing on
Are there any other things you were expecting to be available? |
That sounds great! I was just looking at this last night even, how funny. I did discover that The point is, it's not that far away and I think it's feasible to try and retrieve it. |
What are you thinking for the case where you have two subdirs in |
Yeah, that's what I was thinking. Whatever value that the user passes to |
I haven't figured out exactly how you're assembling the data for the template, but I'm thinking something like: var self = this;
this.engine = function (viewPath, options, callback) {
options.view = this;
self.renderView(viewPath, options, callback);
}; Where I know it's not nearly as clean as before, but it does accomplish the goal without too much extra code. Thoughts? |
So Express passes a res.render('home');
res.render('home.hbs');
res.render('./views/home');
res.render('./views/home.hbs'); That said, what I'll do is something similar to how I process the partials and create their names; i.e., |
@dominicbarnes okay, added. Check out the commit linked above. |
Sounds good to me! I can't wait to see this merged, I'll be trying it out right away. :) |
It would be really helpful to add some more meta to
options.data
before rendering. In particular, I think thatlayout
andview
could be useful:The text was updated successfully, but these errors were encountered: