Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda