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

261
Views
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 answers
Answer question

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 Report
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!