Visualizer only works with handlebars?

Hey, I’m new to PM and very interested in the Visualizer feature, but I’m wondering - are templates only able to access/pass in data from a response with handlebars? Meaning, is there any way I can work with regular old Javascript to handle data/interpolate it into a template? For instance:

var template = `
          <div>{{myresponse.product}}</div>`
       `
    pm.visualizer.set(template, {
        myresponse: pm.response.json()
    })

Works fine - I see the value I expect, which is just the value of a property within the main response object.

However,

var template = `
            <div>${myresponse.product}</div>
            `

pm.visualizer.set(template, {
    myresponse: pm.response.json()
})

Give the error “myresponse” is not defined.

Wondering if anyone has an answer to this/basic tips on using regular JS instead of handlebars inside a template, or just in the visualizer at large (like, is a template required?) Thanks!!

The only thing that’s required is pm.visualizer.set(<template name>) and the template name variable containing the data you want to render.

The data object (the 2nd argument) inside that .set() function is optional.

So you can display that value by refactoring what you have a little bit:

let myresponse = pm.response.json()

var template = `
            <div>${myresponse.product}</div>
            `
pm.visualizer.set(template)

That will render the value in the Visualize tab:

3 Likes

Thanks so much! This is exactly the explanation I was looking for, I knew there had to be a simple way to achieve the basic idea I was looking for without the handlebars side of things… really appreciate it!

1 Like