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

485
Views
How to always pass 'render' parameters in Express

I'm building a website where some parameters need to be passed to the frontend for every page that's loaded (ie text that's used in a navbar that is on everypage). At the moment I'm just including all the parameters in every render line but I'm wondering if there's a more efficient way to do it (in middleware for example). The two parameters below are being used in every render.

return res.render('index', {
    docTitle: i18n.__('home'),
    isLoggedIn: req.session.isLoggedIn,
})
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could create your own render function, where you set the default values and delegate to res.render:

const customResRender = (req, res, page, params = {}) => 
  res.render(page, {
    docTitle: i18n.__('home'),
    isLoggedIn: req.session.isLoggedIn,
    ...params
  });

Then, use it instead of res.render:

app.get("/someHandler", (req, res) => {
  // ...
  customResRender(req, res, "index");
});
over 4 years ago · Santiago Trujillo 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!