I have this template:
.bar
.titleBox
a.title(href=URL) #{title}
Which I want to include multiple times in another page, titles.jade, like so:
#contentBox
include bar
include bar
include bar
And I want each one to have a different value for URL and title.
I have this code in node:
read(function(post){ //post is an array of objects retrieved from a mongodb collection
// I was thinking of using a for loop to iterate through the array
res.render('titles', {title: post[i].title, url: post[i].URL});
How might I achieve my desired outcome?
I'm not sure what these objects represent, but I'll assume for now we are talking about books. If your jade template can get a list of books as a local - e.g. if it's redered like:
res.render('books_index', {books: [{title: 'dune', url: 'http://www.dunenovels.com'},...]})
You can use a mixin. Something like this:
mixin listBooks(books)
each book in books
.bar
.titleBox
a.title(href=book.url)= book.title
later in your template you can render the mixin:
mixin listBooks(books)