【问题标题】:extanding layout page and links on other pages扩展布局页面和其他页面上的链接
【发布时间】:2016-05-27 08:09:55
【问题描述】:

我在我的节点 js 项目中使用 ejs,并为类似的视图使用 html 模板

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

我想将 layout.html 用于我的其他页面,如何扩展它?谢谢!

【问题讨论】:

    标签: html node.js express ejs


    【解决方案1】:

    您可以使用 ejs 或 ejs local 作为引擎。

    在您的应用中:

    app.engine('ejs', require('ejs-locals'));
    app.set('view engine', 'ejs');
    

    在创建模板文件为 .ejs 之后 并且在您的其他 .ejs 文件中需要这样的模板:

    <% layout('template.ejs') -%>
    

    【讨论】:

    • 用html引擎不行吗?
    • 从未尝试过,但也从未见过这种用法的例子。但是你可以毫无问题地使用 ejs - 可以将你的文件扩展名从 .html 更改为 .ejs 并且它会工作
    • 是的,我这样做了,但我只是想使用 html 视图引擎 ((
    猜你喜欢
    • 2021-01-01
    • 1970-01-01
    • 2011-11-03
    • 2015-02-05
    • 2016-12-06
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多