Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

265
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda