I am including a template with the usual {{> someTemplate}}. This works perfectly and I access the relevant data in that template.
Now I am attempting to add an argument to the include, like so {{> someTemplate action="update"}}. And when I do so, the data just goes missing because it no longer appears in the rendered HTML. On the off chance that action is a keyword, I even tried {{> someTemplate abcdefg="update"}} and the data still doesn’t show up.
action="update" sets up a new context, so the former one is not directly accessible anymore.
You can still access it using the ../ syntax in html, or Template.parentData(n) in js.
You can also put the former context back into the new one:
Thank you for the reply. I ended up extending the parent context with a StackOverflow solution. I find it odd that I have to do this myself or use parent accessors to get that data. All I’ve changed is one thing. It shouldn’t overwrite unless I specify as much. Can someone from MDG explain why overwriting is the default case?
Template.registerHelper('extendContext', function(data) {
var result = _.clone(this);
_.each(data.hash, function(value, key) {
result[key] = value;
})
return result;
});
If overwriting was not the default, someone would have asked: "can someone from MDG explain why the parent context is still there?! It breaks the isolation principle! When I call a function, I don’t get all arguments of the function’s caller! "