After discussing with Jerad, I have tried adding console logs to check the
type of the variable.

var test = {{tenantID}}
console.log(typeof test);

This gave the type as number.

And then when I print the following, the result was true.

console.log(test==1);

The issue might be the ifCond registerHelper is not working with the type
number.

Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
    switch (operator) {
        case '!=':
            return (v1 != v2) ? options.fn(this) : options.inverse(this);
        case '==':
            return (v1 == v2) ? options.fn(this) : options.inverse(this);
        case '===':
            return (v1 === v2) ? options.fn(this) : options.inverse(this);
        case '<':
            return (v1 < v2) ? options.fn(this) : options.inverse(this);
        case '<=':
            return (v1 <= v2) ? options.fn(this) : options.inverse(this);
        case '>':
            return (v1 > v2) ? options.fn(this) : options.inverse(this);
        case '>=':
            return (v1 >= v2) ? options.fn(this) : options.inverse(this);
        default:
            return options.inverse(this);
    }
});



On Tue, Sep 15, 2015 at 2:04 PM, Dinithi De Silva <[email protected]> wrote:

> Hi Dakshika,
>
> I have tried out using "===" but it still gives the same result.
>
> Thanks.
>
> On Tue, Sep 15, 2015 at 1:50 PM, Dakshika Jayathilaka <[email protected]>
> wrote:
>
>> Hi,
>>
>> Try with  "==="
>>
>> Regards,
>>
>> *Dakshika Jayathilaka*
>> PMC Member & Committer of Apache Stratos
>> Senior Software Engineer
>> WSO2, Inc.
>> lean.enterprise.middleware
>> 0771100911
>>
>> On Tue, Sep 15, 2015 at 1:31 PM, Dinithi De Silva <[email protected]>
>> wrote:
>>
>>> Hi Dakshika / Jerad,
>>>
>>> I am trying to retrieve the tenantId stored in a session variable into
>>> handlebars js file. The variable "teananID" has the value of the tenant id
>>> (Ex: -1234) but when comparing it with -1234 or any other integer the
>>> condition is always false.
>>>
>>> Please find the piece of code in my handlebar js file below.
>>>
>>> {{#ifCond tenantID "==" -1234}}
>>>        <p>Test1</p>
>>> {{else}}
>>>        <p>Test2</p>
>>> {{/ifCond}}
>>>
>>>
>>> Please note that I have tried printing the variable using console.log
>>> and it gave the value -1234. And also we can compare two strings using the
>>> same way without any issue.
>>>
>>> What could be the missing part in the condition to always become false?
>>>
>>> Thanks.
>>> --
>>> *Dinithi De Silva*
>>> Associate Software Engineer, WSO2 Inc.
>>> m:+94716667655 | e:[email protected] | w: www.wso2.com
>>> | a: #20, Palm Grove, Colombo 03
>>>
>>
>>
>
>
> --
> *Dinithi De Silva*
> Associate Software Engineer, WSO2 Inc.
> m:+94716667655 | e:[email protected] | w: www.wso2.com
> | a: #20, Palm Grove, Colombo 03
>



-- 
*Dinithi De Silva*
Associate Software Engineer, WSO2 Inc.
m:+94716667655 | e:[email protected] | w: www.wso2.com
| a: #20, Palm Grove, Colombo 03
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to