目前,所有网页均来自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'));
...
});
由于
答案 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
});