I must be overlooking something but I don’t manage to get a variable from node.js to pass on into a js script object/variable in .ejs.
I have a route:
app.get('/simulation', (req, res) => {
console.log("simulation results route requested");
hotels = [
{
hotel: 'Hotel Tevini ****superior'
}
];
console.dir(priceTravelers, {depth:null});
res.render('simulation/simulation', {jsonData: hotels});
});
And I want that data to be parsed in to a variable in the .ejs file.
I have tried
const data = <%= jsonData %>;
in the .ejs but that does not seem to work.
Any thoughts?
I tried several things like data = JSON.parse(<%= jsonData %>);
.
Stringify the data on render to send first and then parse on the .ejs side but that gives [object][object] back etc.