handlebars templating engine


jsreport handlebars engine uses handlebars library and therefore is fully compatible with it. This page contains only some examples. Full documentation is located at http://handlebarsjs.com

Data binding

You can use values from report input data using {{...}} tags.

Assuming following input data object

    "title": "Hello world"

you can use {{title}} to pring Helo world



Assuming folowing input object:

    "shouldPrint" : true,
    "name" : "Jan Blaha"

Then you can use shouldPrint bool value in the if condition. For more sophisticated condition see Helpers section.

{{#if shouldPrint}}


Assuming following input data object

    "comments": [ {"title": "New job", "body": "js developers wanted at... " }]

You can simply iterate over comments using each

{{#each comments}}


jsreport report template contains content filed with javascript templating engines tags and helpers field where you can place some javascript functions and then use them.

For example you want to have an upper case helper function. You can register a global function inside a helpers field with the following code:

function toUpperCase(str) {
    return str.toUpperCase();

And then you can call function in handlebars using:

say hello world loudly: {{{toUpperCase "hello world"}}}

Calling helper from helper

Handlebars allow calling a helper from another helper through Handlebars.helpers.helperName. The following snipped shows how to do this in jsreport helpers section.

const  Handlebars = require('handlebars')

function helperA () {
  return  'helperA'

function helperB () {
  return  Handlebars.helpers.helperA()

Thirdparty helper libraries

There are plenty of thirdparty libraries providing additional handlebars helpers like handlebars-helpers or handlebars-intl. To use such a library in jsreport, you need to install it from npm and then require it at the top of the template's helpers.

npm install handlebars-intl

const handlebars = require('handlebars');

const HandlebarsIntl = require('handlebars-intl');

npm install handlebars-helpers

const handlebars = require('handlebars');

const helpers = require('handlebars-helpers')({
  handlebars: handlebars