Answer the question
In order to leave comments, you need to log in
Express + express-handlebars displaying certain data from the database on each page?
Friends, I'm sorry this question may seem stupid! I have partilas footer.hbs and head.hbs , in these templates from the mongodb database, I want to add micro-markup data that is stored in the microdata collection, for example, this general data should be displayed on each page.
I know one way, to pass data with each request. But maybe there is a more concise solution?
Answer the question
In order to leave comments, you need to log in
app.use(async (req, res, next) => {
try {
res.locals.microdata = await getMicrodata();
next();
} catch (error) {
next(error);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question