I Get [object Promise] from handlebars helper, when i use childTemplate.call()
-
Since a few days i play around with jsReport to see if we could use it. And I am seriously stoked about it.
It could become a serious competitor for jasperreports for us.I want to pass the content (innerhtml) of the whole handlebar to a child template and use it there. Only I don't have a working idea how to make this work.
-
Okay, I found the solution myself.
function notificationTemplate(name, title, color, opts) { return childTemplate.call({ ...this, // add extra param data: { title, color, innerhtml: (typeof opts.fn == 'function') ? opts.fn(this) : (typeof opts.inverse == 'function') ? opts.inverse(this) : null }, }, { name, recipe: "html", engine: "handlebars", }, opts) }
Only I have no idea what the
opts.fn(this)
oropts.inverse(this)
is supposed to be.
But it works.
-
I' m glad you like what we do.
The
opts.fn
evaluate handlebars inside the block helper and returns a string. Theopts.inverse
does the same, but for the block you put into the{{else}}
section.
Documentation:
https://handlebarsjs.com/guide/block-helpers.htmlYour solution looks good, you can even go just with
innerhtml: opts.fn(this)