Nodejs學習-2 express ejs 片段視圖

來源:互聯網
上載者:User

標籤:nodejs   ejs   

在Express架構下,使用ejs模板引擎:

    支援預設的layout布局需要express-partials模組;

    使用include代替partials;

    片段視圖顯示方式也與3.x版不同,採用如下方式:

    routers/index.js 添加:

router.get(‘/list‘, function(req, res) {  res.render(‘list‘,{    layout:false,    title: ‘Express‘,    items: [‘1‘, ‘2‘, ‘3‘, ‘4‘]  });});

    views/list.ejs :

<h1><%= title %> list.ejs </h1><ul>  <% for(var i = 0; i< items.length; i++ ) { %>  <li><%= items[i] %></li>  <% } %></ul>

運行,輸入:http://127.0.0.1:3000/list

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/45/2B/wKiom1PkIuPwVlGxAABrc-cDuqo660.jpg" title="2014-08-08 09:07:00 的螢幕.png" alt="wKiom1PkIuPwVlGxAABrc-cDuqo660.jpg" />

參考:node.js 模板 ejs  在Express ejs 3.*中使用include代替partial和layout

ejs以及替代的include實現方式

本文出自 “颯颯秋風” 部落格,請務必保留此出處http://xjhznick.blog.51cto.com/3608584/1537280

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.