Question: separate data retrieval process from main file while including parts in EJS

Question

separate data retrieval process from main file while including parts in EJS

Answers 0
Added at 2017-01-03 18:01
Tags
Question

I do <% include header.ejs %> in most of my ejs files. The header.ejs will contain dynamic data from the database.

I want to separate the getting of the data from the header and getting the data for the rest of the data on the page.

In the past I have done something like on the index page, send the data to the res.render("/index") included the data for the index page and the header. I would have to do the same for the about page.

I also tried res.locals in an app.use(/) all rout type of thing. I think that worked but I think there is an issue with redirects and sometimes the data didn't show. I read that redirects and res.local don't work good together.

I want to do something like

app.get("header.ejs",{headerData : fromDb})

Answers
Source Show
◀ Wstecz