Handlebars get access to data in script tag

Viewed 1054

I've got a plain handlebars template that I'm passing through puppeteer to generate a pdf. I'm able to access the data through the body normally but can't seem to do so in a JS script tag. My data looks something like this.

const context = { data: [ {..some data}, {...some data}, {...some data}] }

I'm trying to access it in my script tag like

const data = "{{ data }}"

but all I get back when I console log this in my script tag is

[object Object],[object Object],[object Object]

When I check the typeof, it comes back as a string.

1 Answers

Solved it by making a simple helper to stringify the data. (I have my helpers in a helper object)

json: function(obj) {
    return JSON.stringify(obj);
  }

Then in my JS script I just call it with the triple brackets

const wedges = {{{ json data }}}
Related