Node08---ejs template

Source: Internet
Author: User

iv. template engine <a href= "<%= url%>" ></a> data binding, It becomes a complete HTML string. Front of the template, we now want to learn is the background of the template. Backstage template, the famous two, the first is called Ejs, the second one is called Jade. Is the NPM third-party package. First say ejsembedded JavaScript templates background template engine    <ul> for        (var i = 0; i < news.length; I + +) {%>            <li><%= news[i]%></li>        <%}%>    </ul>var dictionary = {          a:6,          News: ["1 class is too good", "high-paying employment", "ha ha ha haha"]};

14.js

/**/var ejs = require ("Ejs"); // Templates var string = "So happy, today I bought iphone<%= a%>s"; // Data var data = {    6}; // Data Binding var html = Ejs.render (string, data); // output console.log (HTML);

15.js

/** * Created by Danny on 2015/9/20 16:59.*/varEjs = require ("Ejs");varFS = require ("FS");varHTTP = require ("http");varServer = Http.createserver (function(req,res) {fs.readfile ("./views/index.ejs",function(err,data) {//Binding Templates        varTemplate =data.tostring (); varDictionary ={A:6, News: [{"title": "Chen Wei I Love You", "Count": 10},                {"title": "Haha haha", "count": 20},                {"title": "Tease You", "Count": 30}            ]        }; varHTML =Ejs.render (template,dictionary); //ShowRes.writehead (200,{"Content-type": "Text/html;charset=utf8"});    Res.end (HTML); });}); Server.listen (3000);
Index.ejs
<!doctype html> for (var i = 0; i < news.length; i++) {                if(News[i].count >) {        %>                <li><%= news[i].title%></li>        <%                }            }        %>    </ Ul></body>

Ejs template efficiency is not high, jade engine high efficiency, difficult

Node08---ejs template

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.