Search code examples
javascriptbackbone-viewshandlebars.jshandlebarshelper

How to access object from parent in custom if helper?


The ../../Message.NotAvailable in the ifequal helper doesn't seem to work but if i provide a string "Hello" to compare with type it works fine and comes inside the loop

{{#ifequal type ../../Message.NotAvailable}}
    <li id="{{id}}"><a href="#">{{../../../Message.NotAvailable}}</a> </li>
    {{/ifequal}}

My helper:

  Handlebars.registerHelper('ifequal', function(value1, value2, options) {
    if(value1 === value2) {
        return options.fn(this);
    }
    return options.inverse(this);
});

EDIT:

I have tried removing ../../ from the variable as well doesn't seem to work.


Solution

  • If Message.NotAvailable is in the parent template scope, use ../Message.NotAvailable.

    The ../ path segment references the parent template scope, not one level up in the context. enter image description here