Y
Y
yaroslav19962020-02-02 12:46:33
MongoDB
yaroslav1996, 2020-02-02 12:46:33

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

1 answer(s)
V
Vladlen Hellsite, 2020-02-02
@yaroslav1996

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 question

Ask a Question

731 491 924 answers to any question