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

262
Vistas
Get options sent to pug with space in the name

I am trying to send JSON options into a pug file with a space in the attribute names.

For example, inside an express get request:

let json = {"Attribute Name With Spaces": "Value"}
res.render('loader.pug', json);

How do I access this data in the pug file? It is difficult to change the format of the json because it is external and not something I made myself.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Pug makes locals available under the locals property so you can simply use the following...

h1= locals["Attribute Name With Spaces"]
p Here's the var #{locals["Attribute Name With Spaces"]}

I couldn't find any official documentation for this so it might not always be a reliable option.


Another option to make this easier would be to simply bundle all your json properties under a single object...

res.render("loader.pug", { props: json });

Then you can use something like this

h1= props["Attribute Name With Spaces"]
p #{props["Attribute Name With Spaces"]}

Alternately, transform your object to normalise the keys

res.render(
  "loader.pug",
  Object.fromEntries(
    Object.entries(json).map(([key, val]) => [key.replaceAll(" ", "_"), val])
  )
);

and use

h1= Attribute_Name_With_Spaces
about 4 years ago · Juan Pablo Isaza Denunciar
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