How do I loop over an object and output markdown as part of the loop in my jade template?
block content
section.content
h1= title
p Welcome to #{title}
ul
each post in posts
li!= :markdown
post
{
"post1": "#Hey\nHow are you?",
"post2": "#Hello\nworld"
}
But I don't seem to be able to get the markdown to work inside of the loop, I've read over the documentation and tried Googleing but don't seem to be able to find anything that doesn't require loading another library for markdown in the view when Jade already has it.
I did some more research on the issue and as far as I understand it it is because:
Is compiled at a different time to evaluated scripts such as my != post
Since I could never get :markdown to compile after my post object, I injected the node-markdown module into my views like this.
var MarkDown = require('node-markdown').MarkDown;
res.render('blog', {
"title": name,
"md" : Markdown,
});
And in my view I used this
each post in posts
li!= md(post)
And it all appeared to work, I've left the title var out of my example because it wasn't really part of the fix, just asthetic.