How to refer to the Ejs template engine in the Express framework

Source: Internet
Author: User

Original address: http://www.cnblogs.com/greenteaone/p/3685733.html

1. How to install the Ejs template engine in a project

Use the following command to establish the basic structure of your Web site in the Nodejs guide:

Express-t Ejs Microblog

Continue running after running this command

CD microblog && npm Install (dependency properties of the installation project),

found that the installed template engine is jade, not ejs. The reason is that the current version has no-t this command, instead

EXPRESS-E microblog

After running this command, continue running CD microblog && NPM install,ejs template engine is installed

But express3 above version of the layout by default to cancel, so now in the Views folder does not generate Layout.ejs.

2. When Ejs is installed, how to use the Ejs layout template

Installing Express-partials

Switch to the project directory in cmd, run npm install express-partials or

package.jsonadded in the dependencies inside "express-partials": "*" . Then run under the project directory npm install .

  然后在app.jsInside quoteexpress-partials,引用方法:

1. Adding referencesvar partials = require(‘express-partials‘);

2. app.set(‘view engine‘, ‘ejs‘); Add the followingapp.use(partials());

Invoke the sample where you need to reference the template layout:‘模版名称‘

app.get(‘/reg‘, function (req, res) {  res.render(‘reg‘, {    title: ‘用户注册‘,    layout: ‘template‘  });    });

How to refer to the Ejs template engine in the Express framework

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.