如何在express.js中集成HTML模板

时间:2015-05-16 09:19:35

标签: jquery node.js express socket.io pug

如何在express.js中包含我的html / js / css文件? 有什么方法可以管理模板吗?

我想只使用HTML(没有玉)。

    <head>
      <DATA>
    </head>
    <header>
         <?php include('includes/header.html'); ?>
    </header>
    <topnavigation>
         <?php include('top_navigation/header.html'); ?>
    </topnavigation>

    <content>
         <?php include('website/header.html'); ?>
    </content>

    <footer>
         <?php include('includes/content.html'); ?>
    </footer>

1 个答案:

答案 0 :(得分:0)

Follow this tutorial

在本教程中使用了.ejs模板引擎,但您只需将.ejs替换为.html,之后只需更改一件事。

更改此行: -

// set the view engine to ejs
app.set('view engine', 'ejs');

用这个: -

 app.engine('html', require('ejs').renderFile);  

现在你可以使用普通html页面作为模板引擎了