0

I created

Handlebars.registerHelper('ifItIsBelow3',function(value){
  if (value < 3)
  {
    return true;
  }else
  {
    return false;
  }
});

and wanted to use is on the page

in

{{#ifItIsBelow3 {{@index}}}}
              <div>{{artists.0.name}}: {{name}}</div>
              <div idName="{{artists.0.name}}: {{name}}" id="{{id}}1" style="background-image:url({{album.images.0.url}})" data-track-id="{{id}}" class="cover"></div>
          {{/ifItIsBelow3}}

but my handlebar helper is not working; I have message

Uncaught Error: Parse error on line 3: ... {{#ifItIsZero {{@index}}}}

in browser.

I loaded my handlebarHelper.js as a script on the page. I am not sure if it was really loaded. Should I place it in some very specific place?

all hints are welcome

Marcin

marcinwal
  • 169
  • 10

1 Answers1

0

Your code should be as follow:

Javascript:

Handlebars.registerHelper('ifItIsBelow3',function(value){
  if (value < 3){
    return true;
  }else{
    return false;
  }
});

HTML:

{{#ifItIsBelow3 {{@index}}}}
     <div>{{artists.0.name}}: {{name}}</div>
     <div idName="{{artists.0.name}}: {{name}}" id="{{id}}1" style="background-image:url({{album.images.0.url}})" data-track-id="{{id}}" class="cover"></div>
 {{/ifItIsBelow3}}

Or for Index follow below answer:

How to get index in Handlebars each helper?

Thanks:

Community
  • 1
  • 1
Naitik
  • 1,455
  • 15
  • 26