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)); // gives error
});
Custom Helper Rendering:
{{#List dataList}}
{{> widgets/toDoList}}
{{/List}}
It produce error
SyntaxError: Unexpected token u in JSON at position 0
Whereas, it is working with the static data
{{#List '[
{
"id": 1,
"title": "Arrange meeting",
"date": "Today 10:35 | By Admin",
"completed": true
},
]' }}
{{> widgets/toDoList}}
{{/List}}
When I have add full json code in {{#List full_json_code_here}} with single quotes then works perfectlycan you please explain it ? or better add the use case in the question, when its workingres.render('view-name', data).