Dragunov
Dragunov

Reputation: 985

Dynamic html pages with Jade, NodeJS, Express

I have a big json object containing cell data from a sample spreadsheet that has been retrieved from redis keystore. I want to show it in a html table format in the jade template. But for now, all I can show it as is a json string.

I am also unclear about how to generate dynamic web pages using jade/express.

Sample JSON string am trying to pass:

{"1A":"Cell Data 1", "1B": "Cell Data 2",...}

It is data from an excel spreadsheet.

Please help me to clear this doubt.

Upvotes: 9

Views: 14619

Answers (1)

generalhenry
generalhenry

Reputation: 17319

table
  thead
    tr
      th Name
      th Food
  tbody
    - var items = [{name:'Dean',food:'Chicken'}, {name:'Paul',food:'steak'}]
    - each item in items
      tr
        td= item.name
        td= item.food

outputs

<table><thead><tr><th>Name</th><th>Food</th></tr></thead><tbody><tr><td>Dean</td><td>Chicken</td></tr><tr><td>Paul</td><td>steak</td></tr></tbody></table>

or more practically than defining the items array of objects in jade

var items = dynamicallyGenerateYourJson();
res.render('table', {
  items: items
});

Upvotes: 17

Related Questions