I have 4 different routes in my routes> intro.js file and you want to pass the same variable for each route.
(I am using nodejs express with ejs view engine)
// intro.js file
var something = {
common: 'common',
different: {
test1: 'test1',
test2: 'test2',
test3: 'test3',
test4: 'test4'
}
}
router.get('/test1', (req, res) => {
res.render('test1', {common: something.common, different: something.different.test1});
}
router.get('/test2', (req, res) => {
res.render('test2', {common: something.common, different: something.different.test2});
}
router.get('/test3', (req, res) => {
res.render('test3', {common: something.common, different: something.different.test3});
}
router.get('/test4', (req, res) => {
res.render('test4', {common: something.common, different: something.different.test4});
}
There seems to be a better way to pass a common (something.common) variable for each route (ejs view files) as something.common repeats.
In fact, the view file that receives this shared variable is a regular view file. This view file is included in the file test1, test2, test3, test4 separately, using
<% include 'view_file' %>
Is there a way to pass this repeating variable to all routes at once?
Having some difficulties, any advice can really be appreciated.