-
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
Including partials dynamically #121
Comments
Dynamic partials are supported in Handlebars 3.0. See: handlebars-lang/handlebars.js#941 So you would do: {{#each modules}}
{{> (this.name) }}
{{/each}} |
@ericf I must be missing something then...
This is what I have in the code:
( If I print |
So I didn't try to the code myself… let me know what you figure out. |
Looking at the unit tests the subexpression needs to be a helper. Something like this: var app = express();
app.set('view engine', 'hbs');
app.engine('hbs', exphbs({
helpers: {
partial: function (name) {
return name;
}
}
})); {{#each modules}}
{{> (partial this.name) }}
{{/each}} |
Hi Justin! I took a look at this, and it appears to be a quirk of how Handlebars processes subexpressions: "Subexpressions do not resolve variables so whichPartial must be a function." In your code,
needs to be:
Kinda awkward. Alternatively, you could perform a
I've tested both these approaches in v.2.0.1 of express-handlebars, and both work without any custom helpers required. I'm using |
Apparently your dynamic partials need to parsed as a function which returns a string. |
I'm having trouble with dynamic partials as well. I thought I was doing it correctly but I keep receiving a partial not found error. Oddly, the error disappears if I mention the partial in a commented handlebars statement, as if that commented statement loaded the template, so now the dynamic loading works. Please see the details here: http://stackoverflow.com/questions/36438434/handlebars-and-node-dynamic-partial-not-found Can you anyone help? |
If you're using the handlebar-helpers library you can use a standard string function such as
|
Hi,
I have been looking for a simple way to dynamically render partials based on a value in an
{{#each ...}}
loop.For example:
This would allow me to load partials based on data rather than putting a lot of logic in the template.
The text was updated successfully, but these errors were encountered: