node.js - templates / rendering - 如何为我的一个视图排除或指定一个替代layout.mustache?

时间:2012-10-24 07:48:11

标签: node.js templates express connect mustache

目前,所有网页均来自views/layout.mustache文件和特定于网页的views/page.mustache模板

我想在我的应用程序中呈现某个视图时使用备用layout.mustache和/或全部跳过layout.mustache。这样做的理想方式是什么?

以下是我的app.configure

的摘要
app.configure(function(){
    ...
    app.set('views', __dirname + '/views');
    app.register(".mustache", require('stache'));
    ...
});

由于

1 个答案:

答案 0 :(得分:1)

您使用的是哪个版本的快递?在v3.0中,布局的概念是removed

V3.0引入了blocks的概念。我不使用mustache,但玉的例子如下:

// my-template.jade
extends my-layout

block head
  script(src="myfile.js")

block content
  h1 My page

// my-layout.jade
doctype 5
html
  head
    title My title
    block head
  body
    #content
      block content

使用extends,您可以选择所需的“父”布局。受支持的模板引擎概述在快递wiki

在3.0之前的快速版本中,您可以在渲染时指定布局

res.render('index', {
  title : 'Page with distinct layout', 
  layout : 'layout.mustache'
});

或禁用某些视图的布局

res.render('start', {
  title : 'Page without layout', 
  layout : false
});