有什么方法可以使用Express + Node.js的多视图引擎吗?

时间:2022-03-31 18:27:24

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

场景:我使用Node开发了一些事务页面。作为视图引擎和MongoDB, Express + Handlebars。

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

现在的问题是,在模块集成过程中,我得到了一些构建在Express + Jade作为视图引擎上的页面。

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

问:如何整合建立在车把上的网页?

2 个解决方案

#1


17  

  1. Add both engines and consolidate.js in your package.json
  2. 添加引擎和合并。js中package.json
  3. In yourapp.js

    在yourapp.js

    var engines = require('consolidate');

    var引擎=要求(“巩固”);

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

    app.engine(‘玉’,engines.jade);

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

    app.engine(车把,engines.handlebars);

More info here

更多的信息在这里

#2


6  

Express 4.0 and up solution (until it changes again)

Express 4.0和up解决方案(直到它再次发生变化)

  1. NPM install the engines you need.

    NPM安装你需要的引擎。

    // some examples
    npm install ejs
    npm install pug
    npm install handlebars
    
  2. Set the engines to use in your app.js.

    设置要在app.js中使用的引擎。

    app.set('view engine', 'pug');
    app.set('view engine', 'ejs');
    
  3. Render your template, be sure to set the file extension.

    呈现模板,请确保设置文件扩展名。

    // forces usage of the respective render engine by setting the file extension explicitly.
    res.render( 'about.ejs', { title: 'About' } );
    res.render( 'about.pug', { title: 'About' } );
    
  4. Documentation for more usage examples.

    更多使用示例的文档。

#1


17  

  1. Add both engines and consolidate.js in your package.json
  2. 添加引擎和合并。js中package.json
  3. In yourapp.js

    在yourapp.js

    var engines = require('consolidate');

    var引擎=要求(“巩固”);

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

    app.engine(‘玉’,engines.jade);

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

    app.engine(车把,engines.handlebars);

More info here

更多的信息在这里

#2


6  

Express 4.0 and up solution (until it changes again)

Express 4.0和up解决方案(直到它再次发生变化)

  1. NPM install the engines you need.

    NPM安装你需要的引擎。

    // some examples
    npm install ejs
    npm install pug
    npm install handlebars
    
  2. Set the engines to use in your app.js.

    设置要在app.js中使用的引擎。

    app.set('view engine', 'pug');
    app.set('view engine', 'ejs');
    
  3. Render your template, be sure to set the file extension.

    呈现模板,请确保设置文件扩展名。

    // forces usage of the respective render engine by setting the file extension explicitly.
    res.render( 'about.ejs', { title: 'About' } );
    res.render( 'about.pug', { title: 'About' } );
    
  4. Documentation for more usage examples.

    更多使用示例的文档。