具有变量的玉模板(nodejs服务器端) [英] Jade template with variables (nodejs server side)

查看:148
本文介绍了具有变量的玉模板(nodejs服务器端)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想显示一个联系人列表,因为我已经将每个联系人div转换成了翡翠代码,但是我仍然需要填写相关的字段。我可以在服务器端这样做吗?我正在使用nodejs作为服务器代码。联系人的玉模板是:

  // 
img-cont
.img-cont
//
img-cont
.left-img
//
left-img
.img-box
img(src ='资产/ img / img.jpg',alt ='')
.name
h6
span John Doe
img(src ='assets / img / star-b.png ',alt ='')
p
strong电话号码:
| +1 234 567890
p
strong电子邮件地址:
a(href ='mailto:mail@company.com')mail@company.com
//
left- img
ul.share-ul
li
a.edit(href ='#')编辑
li
a.share(href ='#')分享
li
a.delete(href ='#')删除
//
img-cont

所以代替John Doe和随机的电话号码,如果有一种方式来表示我想要的变量,那么nodeJS代码将会保持正确的值在那里,将玉翡翠添加到主玉页,然后转到下一个联系人,等等。所以类似的内容: http://embeddedjs.com/



我正在使用express作为Nodej的框架。

解决方案

是的,您可以在调用render时传递对象与数据

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

然后在玉里面你可以做

  span#{pageData.name [0]} 

或if你想要一个循环

  pageData.name中的每个项目
span#{item}

您可以在github页面上找到更多信息 https://github.com/visionmedia/jade


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:mail@company.com') mail@company.com
      //
        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.

解决方案

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

这篇关于具有变量的玉模板(nodejs服务器端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆