{{if }} conditional statement errors

  • i am looping thru a json data object and doing a if conditional statement like this

    {{#each results}}
    {{#if checkraceid raceID == true}}

    i have a function called checkraceid like this:

    function checkraceid (id) {
    if (id != myraceid) {
    myraceid = id;
    return false;
    return true;

    why does it always error on the {{#if}} statement?
    keeps showing this error: Parse error on line 10: ...checkraceid raceID == true}} -----------------------^ Expecting 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'EQUALS' logs

    i even tried using {{if }} by removing the # but still error

    what is the correct way to do a conditional statement like that?

  • I am afraid handlebars if helper doesn't support passing a custom condition like raceID == true.
    You should pass a single variable or make your own if helper if you need something more complicated.

  • thank you
    thats the conclusion i came up with and have gone a different route to customize my json data structure in my web api

  • In the documentation of version 2.8 I found this example

    {{#if (moreThan2 users)}}More than 2 users
    {{ else }} Less or equal to 2 users

    You can try
    {{#if (checkraceid raceID)}}

    No spaces between {{#if

    Hope this helps someone using old versions.

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.