X
X
Xbbv12016-08-27 23:26:34
JavaScript
Xbbv1, 2016-08-27 23:26:34

How to check equality of variables in handlebars?

How can validation be implemented in this way? {{#if innNumber === this.inn}}YES!{{/if}}
innNumber is passed to the template function when called
. As a result, this is necessary so that in the loop when outputting from json, for example, highlight the line if the value matches

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Moiseykin, 2016-09-02
@moiseykin

You can register Helper:

Handlebars.registerHelper('iff', function(v1, v2, options) {
  if(v1 === v2) {
    return options.fn(this);
  }
  return options.inverse(this);
});

And write like this:
{{#iff v1 v2}}
    {{v1}} === {{v2}}
{{else}}
    {{v1}} != {{v2}}
{{/iff}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question