I have multiple objects in array of locals in my routes and would like to render each at the time.
Example
// routes.js
const routes = {
path: '/posts/:id',
view: 'posts',
locals: [
{
id: 'how-to-write-short',
title: 'How to write short',
description: 'The art of painting a thousand pictures with just a few words',
date: '23 Mar 2018',
issue: '1'
},
{
id: 'the-glamour-of-grammar',
title: 'The glamour of grammar',
description: 'A guide to the magic and mystery of practical English',
date: '01 April 2018',
issue: '2'
}
]
}
Right now, this renders the last objects in array when I visit either link http://localhost:3000/posts/how-to-write-short or http://localhost:3000/posts/the-glamour-of-grammar.
// server.js
const express = require('express')
const routes = require('./routes')
const app = express()
app.set('views', 'src/pages')
app.set('view engine', 'js')
app.engine('js', require('./engine'))
app.get(routes.path, function(req, res) {
res.render(routes.view, routes.locals)
})
app.listen(3000)
What's a better to render each e.g routes.locals[0], routes.locals[1], and ...?
localsas an array. Put that up as well cause I think that'll help a lot.