Nodejs Express Framework works with Ejs templates and Jade templates in one project

Source: Internet
Author: User

In some projects, such as you take over someone else's project and you don't want to use the Ejs, or you don't want to use the egg-sore jade. You do not want to rewrite the previous page, then you may now need to introduce a new Ejs or Jade module, you just need to do the following two steps may be completed using two templates work

1.consolidate.js

CD to project directory:

NPM Install consolidate--save

Open the project's App.js (maybe your name is other)

Take the shape of the app.js like the code snippet below

App.set (' View engine ', ' Jade ');

Switch

var engines = require (' consolidate '); App.engine (' Jade ', Engines.jade); App.engine (' html ', Engines.ejs);//or use these/ /app.engine (' Jade ', require (' Jade '). __express);//App.engine (' HTML ', require (' Ejs '). RenderFile); App.set (' View Engine ', ' Jade ');

You can restart the project.

2. A little problem

In one of my project A, the code I actually used was

var engines = require (' consolidate '); App.engine (' Jade ', Engines.jade); App.engine (' html ', Engines.ejs);//App.engine ( ' Jade ', require (' Jade '). __express);//App.engine (' HTML ', require (' Ejs ') renderfile); App.set (' View engine ', ' Jade ') ;//More than one line App.set (' View engine ', ' html ');

This notation can be used in project a, but found in another project B cannot parse the jade template

In Project B, you can only use the

var engines = require (' consolidate '); App.engine (' Jade ', Engines.jade); App.engine (' html ', Engines.ejs); App.set (' View Engine ', ' jade ');//or//app.engine (' Jade ', require (' Jade ') __express);//app.engine (' HTML ', require (' Ejs '). RenderFile);//app.set (' View engine ', ' Jade ');

Ask the Friends of the park to help answer the question why?

EJS Jade Consolidate version consistent Express version 4.12.x

 

Nodejs Express Framework works with Ejs templates and Jade templates in one project

Related Article

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.