user13836591
user13836591

Reputation:

Getting data from backend and displaying in Pug

MongoDB --> Node.js --> Pug

I am trying get data from mongodb and show it in pug. Here is my code:

router.get("/", isLoggedIn,  (req, res) => 
{
    res.status(200).send(pug.renderFile("./views/menti/takvim.pug", 
    {
        tasks: req.session.user.tasks,
    }))
})

The code above works fine but the I want to display every information in req.session.user.tasks(req.session.user.tasks is an array) in pug. And here is my pug code:

html
    head
    body
      .main
        .tasks

I want add list with tasks which I get from MongoDB and Node.js. How can I do that?

Thanks.

Upvotes: 0

Views: 1064

Answers (1)

antonku
antonku

Reputation: 7665

You can iterate over tasks array and display properties of each task with the following template:

ul
  each task, index in tasks
    li= index
      ul
        each val, key in task
          li= key + ': ' + val

Upvotes: 1

Related Questions