Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
handlebars js - How to avoid replacing handlebars placeholders / tokens with empty string, if they dont exist in the object passed in

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 )

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!