-
Notifications
You must be signed in to change notification settings - Fork 2k
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
each overwrites data in the "data" property. #1327
Comments
I would be helpful if you could separated this problem from The would be helpful for examining the problem. |
I think this problem is because how consolidate implements handlebars. If you look at exports.handlebars.render = function(str, options, fn) {
return promisify(fn, function(fn) {
var engine = requires.handlebars || (requires.handlebars = require('handlebars'));
try {
for (var partial in options.partials) {
engine.registerPartial(partial, options.partials[partial]);
}
for (var helper in options.helpers) {
engine.registerHelper(helper, options.helpers[helper]);
}
var tmpl = cache(options) || cache(options, engine.compile(str, options));
fn(null, tmpl(options));
} catch (err) {
fn(err);
}
});
}; It is passing the data object into the compile method. You can see it reproduced here: https://jsfiddle.net/9D88g/105/ |
Should I move this ticket over to the "consolidate" people? |
I'll have a look. Let me see if I understand what your problem ist. |
No, keep it here. I think you did a pretty good job extracting the problem and it definitely looks wrong to me.
correct? |
yeah. (with the obvious exception of the line break) |
It works, if you change "data" to "datax" (https://jsfiddle.net/9D88g/111/) |
Thanks. Luckily I discovered this before I even created the ticket. The problem seems to be the very specific property |
Well, may be it is something for the consolidate people, maybe not. There room to argue...
Yes, that is problematic because of this piece of code. Now, I don't fully understand why On the other hand, it can be argued that Could you open an issue at |
Oh, I didn't see your last post... I think I will have a look what could be done for not altering the options during compilation. I don't know the code well enough yet to see if it has any impact on the interface. But this might take a while and I can't continue right now. |
I'll raise the issue to the consolidate people as well and link to this issue. |
Perhaps the best thing is to clone the options went they are passed in, so that they can be immutable. Not ideal, but might be enough. I have opened a ticket with |
Fixes handlebars-lang#1327 - This commit creates a shallow copy of the "options" passed to Handlebars.compile() in order to prevent modifications - Note that "new Handlebars.Compiler().compile(..., options)" still modify the options object. This might change in the future, if anybody needs a fix for that.
I have opened a PR, if anyone would like to comment, please do it there. |
After a broken 4.0.9-release (because Object.assign is not supported by IE), this issue is now resolved in 4.0.10 |
I am using
handlebars
as the templating engine of agulp-metalsmith
build system. I am using themetalsmith-data-loader
to load a JSON file into the adata
property; however, when I go to access that property in then handlebars template it is not the value oftrue
. It seems to be linked to the access of the@index
in an each block helper.I presume the problem is in:
handlebars.js/lib/handlebars/helpers/each.js
however, I don't know enough about the expected params to really grok the problem.The text was updated successfully, but these errors were encountered: