mardi 5 novembre 2019

If condition in ember handlebars

I have an ember helper method as below

export default () => { 
        Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
            if (params[3]) {  //handle case insensitive conditions if 4 param is passed.
                params[0] = params[0].toLowerCase();
                params[2] = params[2].toLowerCase();
            }

        let v1 = params[0];
        let operator = params[1];
        let v2 = params[2];

        switch (operator) {
            case '==':
                return (v1 == v2);
            case '!=':
                return (v1 != v2);
            case '===':
                return (v1 === v2);
            case '<':
                return (v1 < v2);
            case '<=':
                return (v1 <= v2);
            case '>':
                return (v1 > v2);
            case '>=':
                return (v1 >= v2);
            case '&&':
                return !!(v1 && v2);
            case '||':
                return !!(v1 || v2);
            default:
                return false;
    }
}); 
 }

I am trying to call it from my hbs file as below


But I am getting the following error, can somebody suggest me something please, thank you.

contacts.hbs:41 Uncaught Error: Module build failed (from ./.webpack/webpack-handlebars.js):
Error: if doesn't match each - 372:59
    at validateClose (C:\SourceCode\IMS\Development\IMS\IMS.Ember\node_modules\ember-source\dist\ember-template-compiler.js:11014:13)
    at Object.prepareBlock (C:\SourceCode\IMS\Development\IMS\IMS.Ember\node_modules\ember-source\dist\ember-template-compiler.js:11125:7)
    at Object.anonymous (C:\SourceCode\IMS\Development\IMS\IMS.Ember\node_modules\ember-source\dist\ember-template-compiler.js:8339:25)
    at Parser.parse (C:\SourceCode\IMS\Development\IMS\IMS.Ember\node_modules\ember-source\dist\ember-template-compiler.js:10142:38)
    at parse (C:\SourceCode\IMS\Development\IMS\IMS.Ember\node_modules\ember-source\dist\ember-template-compiler.js:11271:36)
    at preprocess (C:\SourceCode\IMS\Development\IMS\IMS.Ember\node_modules\ember-source\dist\ember-template-compiler.js:5817:71)
    at precompile (C:\SourceCode\IMS\Development\IMS\IMS.Ember\node_modules\ember-source\dist\ember-template-compiler.js:3949:38)
    at Object.precompile (C:\SourceCode\IMS\Development\IMS\IMS.Ember\node_modules\ember-source\dist\ember-template-compiler.js:8119:37)
    at Object.module.exports (C:\SourceCode\IMS\Development\IMS\IMS.Ember\.webpack\webpack-handlebars.js:15:29)
    at Object.<anonymous> (http://localhost:58799/Ember/dist/templates.js?version=1572992916177.89:22620:7)



Aucun commentaire:

Enregistrer un commentaire