Search code examples
javascriptcoffeescriptmeteorhandlebars.js

global helper is overriding local context in meteor handlebars template


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


Solution

  • 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