Nodejs Express uses Jade template __js

Source: Internet
Author: User

Install Express and Jade modules

NPM Install Express Jade--save

varExpress= Require (' Express ');varapp=Express();// set up a static resource directoryapp. Use(Express.Static(__dirname));// Set the template engine (Use jade templates here app.Set(' view engine ',' Jade ')// Set Template Catalogapp.Set(' views ','./views ')//Port Monitoringapp.Listen( -)// Routingapp. Get('/jade ',function(Req,res) {// can useres.locals.xxPass Value Res.Locals.Persons= [
        {name:'John', Age: -,Sex:'male'},
        {name:'Dick', Age: -,Sex:'female'},
        {name:'Harry', Age: -,Sex:'female'}]// You can also useRes.render ("[, data])to pass the value Res.Render(' Exp1 ',{Info:'This is a background pass.'}); })
New Views/exp1.jade:

DOCTYPEHTMLHTML HeadtitleExpressUseJade  BodyDiv(style="Background-color: #FFCCDD;")ifUse<br> ifInfo spanInfoIt's got a value.<br> Div(style="Background-color: #CCFFDD;")Jadethe basic use h5#Get content:#{Info}  h5!Get content:! {Info}  h5Get content: =Info Div(style="Background-color: #DDFFCC;") eachUse - each per inPersons h5name:#{ per.name} Age:#{ per. Age} Gender:#{ per.Sex}
The results are as follows:



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.