【问题标题】:Jade template inheritance without ExpressJade模板继承无Express
【发布时间】:2012-09-17 05:25:24
【问题描述】:

我想使用 Jade 块继承,但如果我不使用 Express,我不知道该怎么做。根据 Jade 文档,我可以通过简单地添加 app.set('view options', { layout: false }); 在 Express 中使用块继承。如果没有 Express,我该如何实现?

https://github.com/visionmedia/jade

【问题讨论】:

    标签: node.js pug


    【解决方案1】:

    使用翡翠的Template inheritance,根本不需要Express;你只需要翡翠:

    // app.js
    var jade = require('jade');
    
    var options = { pretty: true, locals: {} };
    
    jade.renderFile(__dirname + '/home.jade', options, function (err, html) {
        console.log(html);
    });
    
    // home.jade
    extends core
    
    block body
      h1 Home
    
    // core.jade
    doctype html
    html
      head
        meta(charset='utf-8')
        title Foo
      body
        block body
    

    另一个例子可以在存储库中找到:

    Jade 文档提到为 Express 2.x 设置 'view options' 的原因是因为 Express 自己的(以及 3.x 中的 now defunct)布局是一个竞争特性,应该禁用它以防止在使用 Jade 的继承时发生冲突.

    【讨论】:

      猜你喜欢
      • 2012-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      相关资源
      最近更新 更多