Handlebar #if construct issue
-
I'm using handlebar engine and I need to conditionally hide or show a part of the report based on a data value;
this is a piece of my JSON data
{
"settings": {
"condettaglioprezzi": "true"
},
"offerta": {
"codice": "2017-00007",
"data": "",
"oggetto": ""
},..........then in my report template I inserted
<div class="col-xs-1 text-right" style="width: 12%">{{#if settings.condettaglioprezzi }}€ {{offerta.codice}} {{/if}}</div>
but it does not show the € {{offerta.codice}}
Please help me.
-
Your problem is rather related to handlebars than jsreport, so you should search elsewhere.
My guess that you need to pass bool
true
instead of string"true"
. If you need to evaluate string or complex based condition, you should write your own custom if helper.Handlebars documentation for the help.
http://handlebarsjs.com/block_helpers.html
-
Hi, checking on stackoverflow I got it
as my <div class="col-xs-1 text-right" style="width: 12%">{{#if settings.condettaglioprezzi }}€ {{offerta.codice}} {{/if}}</div> was inside a {{#each}} I had to use {{#if @root.settings.condettaglioprezzi }}
thanks