handlebars js - How to avoid replacing handlebars placeholders / tokens with empty string, if they dont exist in the object passed in
I have template like this let str = "location = {{item.businessLocation}}";
And Data Object like this let data = {"item":{"name":"Mathew"}};
As we can see the placeholder or variable {{item.businessLocation}} is missing in the data object. I do not want the placeholder to be replaced with "" when it is rendered by Handlebars.
I tried implementing the helperMissing helper like below, but it did not work, because the placeholder has a dot in between.
handlebars.registerHelper('helperMissing', function(token) {
return '{{'+token+'}}';
});
Is there any to have handlebars not replace tokens / placeholders with "" , if they don't exist in the object passed in?
I always get the below output
location = ""
What I need is
location = {{item.businessLocation}}
( since item.businessLocation is not present in the data object )