Using the Ejs template engine in the Express site

Source: Internet
Author: User

1. Installation
Start the console at the root of the Web site, enter

  install ejs

Paste_image.png

The package is installed in the Node_modules directory.


Paste_image.png

2 modifying App.js
Modify App.js to change the view engine to Ejs. (and modify the suffix of the template to. html)

  app.set(‘views‘,path.join(__dirname , ‘views‘) ); app.engine(‘.html‘, require(‘ejs‘).__express); app.set(‘view engine‘, ‘html‘);

3 Creating a test page
Create the index.html in the Views folder, as follows:

<! DOCTYPE html><Htmllang="EN" ><Head><Metacharset="UTF-8" ><Title>pivotal Search</Title><MetaName="description"Content="" ><MetaName="Author"Content="" ><!--HTML5 Shim, for ie6-8 support of HTML elements--<!--[if Lt IE 9]> <script src= "Http://apps.bdimg.com/libs/html5shiv/r29/html5.min.js" ></script > <! [endif]--> <!--styles-- <link href="css/style.css" rel="stylesheet" > </head><body> <%= title %></ body> </html>                

Then modify the index.js in the router:


Paste_image.png
/* GET home page. */router.get(‘/‘, function(req, res, next) { res.render(‘index‘, { title: ‘测试11111‘ });});

Original: http://www.cnblogs.com/xuanhun/p/3922847.html

Using the Ejs template engine in the Express site

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.