@index doesn't work in steering wheel

I am trying to use @index in descriptors like this:

<script id="some-template" type="text/x-handlebars-template">
<form class = "pod" action="#" method="post">

<table>
<thead> 
    <th>Name</th> 
    <th>shipment</th> 
    <th>Button</th> 
</thead> 
<tbody> 
    {{#each objects}} 
    <tr> 
       <td>{{name}}</td> 
       <td> <input type="text" id="Shipment"  name={{join 'Shipment' name}}  /> </td>
   <td> <input type="submit" name="actionButton"  value = "update" >  </td>

  {{#if @index == 2 }}       
   <td> 
    <a href ="http://www.datatables.net/examples/api/select_single_row.html{{name}}">  {{name}} </a> 
   </td>

   <td> </td>
      {{/if}}   

 {{/each}} 
</tbody> 
</table> 
</form>
</script>

      

But my if condition doesn't seem to work. Can anyone tell me what I am doing wrong?

+3


source to share


1 answer


Unfortunately, you cannot make comparisons in Handlebars without a dedicated helper.

I can't remember where I found this function, but I had a copy that I used in a node / express script to set a class based on a condition:

app.js



var hbs = require('hbs');

hbs.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);
        case '||':
            return (v1 || v2) ? options.fn(this) : options.inverse(this);
        default:
            return options.inverse(this);
    }
});

      

Hbs template

<div class="{{#ifCond this.order.pushed '==' 'true'}}text-green{{/ifCond}}">Order Status - {{this.order.pushedMessage}}</div>

      

0


source







All Articles