I have a handlebar statement which passes a userid to a helper. I am unsure how this works. The handlebar {{#if isowner ..}}
has .. what is passed here as parameter to the helper funktion?
<template name="test">
...
<table class="table table-hover table-striped">
{{#each tester}}
<tr><
<td>{{#if isowner ..}}
<i class="fa fa-trash removeUser"></i>
{{/if}}
</td>
</tr>
{{/each}}
</table>
...
</template>
Template.test.helpers({
'isowner':function(parent){
return parent.userId === Meteor.userId();
}
});
Obviously this is only true when the userid's are identical. Meteor.userId() is the current user on the client side. So which userid is passed to parent
?
Sure, the name speaks for its self. It must be one level above - but what is this technically? Where does .. go?
..
returns the data context of the parent (enclosing) template or structure -- I rigged up a very simple MeteorPad here that you can maybe play around with to see how it works.
In your case, I think it's probably returning the data context for the test
template. You can console.log(parent)
in your helper to inspect that object and get a bit more info:
Template.test.helpers({
'isowner':function(parent){
console.log(parent);
return parent.userId === Meteor.userId();
}
});
You can find more information about how the ..
is resolved and how it can be used in the spacebars readme.