Update: The bug logged in the selected answer has been fixed by the meteor devs
In my meteor app I have some coffescript making a global helper:
Handlebars.registerHelper "title",->
Session.get("title")
and a piece of template:
{{#each edited}}
<li><a class="left-nav" href="{{entryLink this}}">{{this.title}}</a></li>
{{/each}}
this.title is being overridden by the global helper rather than using the this.title context. (I know because if I remove the global helper it works great)
If I add the following:
Handlebars.registerHelper "debug", ->
console.log this
console.log this.title
to the template like this:
{{#each edited}}
<li><a class="left-nav" href="{{entryLink this}}">{{this.title}}{{debug}}</a></li>
{{/each}}
this.title prints to the console correctly, but is not inserted into the template
Any idea why this is happening or how to make the "this.title" be from the local context
Looks like a bug to me, since https://github.com/meteor/meteor/wiki/Handlebars#expressions-with-dots says:
Paths starting with
this
always refer to properties of the current data context and not to helpers.
I submitted an issue for it: https://github.com/meteor/meteor/issues/1143
I read something about this on the handlebarsjs.com website today. Give this a try:
Handlebars also allows for name conflict resolution between helpers and data fields via a this reference:
{{./name}} or {{this/name}} or {{this.name}}
Any of the above would cause the name field on the current context to be used rather than a helper of the same name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With