You can use app.locals
to pass common data to all templates. From the documentation:
app.locals
Application local variables are provided to all templates rendered within the application. This is useful for providing helper functions to templates, as well as app-level data.
The
app.locals
object is a JavaScriptObject
. The properties added to it will be exposed as local variables within the application.
You can incorporate this into your site in the following manner:
app.locals.navitems = [
{link: 'this', content: 'that'},
{link: 'secondLink', content: 'secondContent'}
];
app.get('/', function(req, res) {
res.render('home/index', {
title: '™DreamTechnologies'
});
});
app.get('/about', function(req, res) {
res.render('home/about', {
title: '™DreamTechnologies - About'
});
});
The navitems
variable will now be available to all templates that are generated with res.render
.