有没有办法在 Express + Node.js 中使用多个视图引擎

有没有办法在 Express + Node.js 中使用多个视图引擎

问题描述:

场景:我使用Node.jsExpress + Handlebars 作为视图引擎和 MongoDB.

Scenario: I had developed some transactional pages using Node.js, Express + Handlebars as view engine and MongoDB.

现在的问题是在模块集成过程中我得到了一些建立在 Express + Jade 作为视图引擎.

Now the issue is during module integration I got some of the pages which are built on Express + Jade as view engine.

问题:如何集成建立在 Handlebars 上的页面 &一些翡翠?

Question: How to integrate pages built on Handlebars & some on Jade?

  1. 在您的 package.json 中添加两个引擎和 consolidate.js>
  2. yourapp.js

  1. Add both engines and consolidate.js in your package.json
  2. In yourapp.js

var engine = require('consolidate');

var engines = require('consolidate');

app.engine('jade',engines.jade);

app.engine('jade', engines.jade);

app.engine('handlebars',engine.handlebars);

app.engine('handlebars', engines.handlebars);

更多信息这里