I need to attach if condition in my handlebar template which checks the equality of string. I have registered a handlebar helper in my script file and using that within my templates. Following is my code.
Test.js file
"use strict"
const handlebars = require('handlebars');
const writeSourceFile = (filename, type) =>
new Promise((resolve,reject) =>
fs.writeFile(filename, type, function(err) {
return err ? reject(err) : resolve();
}));
handlebars.registerHelper('is_status', function(msg, matchMsg, options)
{
if(msg === matchMsg)
return true;
else
return false;
});
const tpl = handlebars.compile(fs.readFileSync('resources/my.html.hbs').toString('utf-8'));
fs.writeFileSync('/home/malintha/tracks.html', tpl(dm));
console.log("Generated source")
res.end();
..............
my.html.hbs file
{{#is_status (location this "mylocation")}}yes{{/is_status}}
I am not getting any output due to an error which is not obvious to me. My template is working fine without this custom is_status check.
What is the problem with my helper or template? Appreciate your insight.