I have a JSON data in dataList variable and I want to add this in custom handlebars helper as a parameter.
var dataList = [
{
"id": 1,
"title": "Arrange meeting",
"date": "Today 10:35 | By Admin",
"completed": true
},
];
Handlebars Custom helper
var Handlebar = require('handlebars');
Handlebar.registerHelper('List', function(data, options){
//console.log(data) //returns undefined
return options.fn(JSON.parse(data));
});
Custom Helper Rendering:
When I have add full json code in with single quotes then works perfectly but I want to add variable of json data (dataList). because I want to change data dynamically. now it produce SyntaxError: Unexpected token u in JSON at position 0 error.
from How to use json in handlebars with nodeJs expressJs
No comments:
Post a Comment