Jade template with variables (nodejs server side)

后端 未结 1 1933
灰色年华
灰色年华 2021-02-01 17:45

So i want to show a contacts list and for that I have transformed each contact div into jade code, but I still have to populate the relevant fields. Can I do that on the server

相关标签:
1条回答
  • 2021-02-01 18:09

    Yes you can do that when you call render pass the object with data

    res.render('your page', {pageData: {name : ['name 1', 'name 2']}});
    

    Then inside jade you can do

    span #{pageData.name[0]}
    

    or if you want a loop

    each item in pageData.name
      span #{item}
    

    You can find more on the github page https://github.com/visionmedia/jade

    0 讨论(0)
提交回复
热议问题