issue with conditional expression {{#if}}

  • hi,
    I have issues with conditional expression {{#if }}. On jsreport playground it's work well, but when I download phantom-pdf it conditional is ignored and show every time

    {{#if conditional_true}}
    show div

        $scope.Download= function () {
          var data = {my json}
            jsreport.serverUrl = 'http://localhost:5488';
            var request = {
                template: {
                    name: 'My_name', engine: 'handlebars', recipe: 'phantom-pdf'
                 data: data
  'myReportName.pdf', request);

  • administrators

    hi! your problem can be related to not passing the correct data to the jsreport request, so when jsreport evaluates the if condition it can't match it to true because maybe there is some field missing in your data, are you sure that you are passing the correct data when rendering from the browser?

  • I used the same json in local jsreport playground and in var request data: { json }, but with different output pdf. I double chekhed all properties in json and they're present when I send it.
    How I can verify which json actually arrives in server jsreport?

  • administrators

    you can write a jsreport script with the following code:

    function beforeRender (req, res, done) {

    and then attach it to your template, after that each data in a request will be logged in console

  • I logged my request and I saw that my json is different. I pass bool but receive a string.
    I send json { "property" : true} , but in my template arrived json { "property": "true"}.
    I tried to solve called custom function , it't work but it is very inconvenient as I have to call it many times for so many checks.
    Can You help me to find another way to convert string to a boolean in jsreport

    function strtobool(conditional, options) {
    if(conditional == 'true') {
    return options.fn(this);

  • I logged my request and I saw that my json is different. I pass bool but receive a string.

    Yes, that is a problem with url encoded forms. We need to better document it and prefer using renderAsync function.
    Please look into the docs and try to use renderAsync

  • thanks a lot !!!

Log in to reply

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