Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  4] [ 2]  / answers: 1 / hits: 62061  / 12 Years ago, thu, march 29, 2012, 12:00:00

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 side? I'm using nodejs for server code. The jade template of a contact is:



//  
img-cont
.img-cont
//
img-cont
.left-img
//
left-img
.img-box
img(src='assets/img/img.jpg', alt='')
.name
h6
span John Doe
img(src='assets/img/star-b.png', alt='')
p
strong Phone number:
| +1 234 567890
p
strong Email address:
a(href='mailto:[email protected]') [email protected]
//
left-img
ul.share-ul
li
a.edit(href='#') Edit
li
a.share(href='#') Share
li
a.delete(href='#') Delete
//
img-cont


So instead of having John Doe and the random phone number if there was a way to signify that i'd like variables over there, and then the nodeJS code would stick in the right values in there and add the contact jade to the main jade page, and then go to the next contact and so on. So something similar to this: http://embeddedjs.com/



I'm using express as a framework for Nodejs.


More From » node.js

 Answers
24

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


[#86527] Wednesday, March 28, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josefinap

Total Points: 548
Total Questions: 125
Total Answers: 106

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;