Skip to content
Myr

Removed "view options" setting. Closes #748

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent d250bf9 · Browse files · 2 files+4 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+4 added−14 removed

  • other:+4 added−14 removed

2 files+4 added−14 removed

modified:docs/guide.md+3 added-13 removed
105 unmodified lines
106107 * _home_ Application base path used for _res.redirect()_ and transparently handling mounted apps.108 * _views_ Root views directory defaulting to **CWD/views**109 * _view engine_ Default view engine name for views rendered without extensions110 * _view options_ An object specifying global view options110 * _view cache_ Enable view caching (enabled in production)111 * _charset_ Alter the default charset of "utf-8"112 * _case sensitive routes_ Enable case-sensitive routing113 * _strict routing_ When enabled trailing slashes are no longer ignored
378 unmodified lines
492mix and match template engines:493494 res.render('another-page.ejs');495497Express also provides the _view options_ setting, which is applied each time a view is rendered, so for example if you rarely use layouts you may set:496 To apply application-level locals, or view engine options may be set using _app.local()_ or _app.locals()_, for example if we don't want layouts for most of our templates we may do:497499 app.set('view options', {500 layout: false501 });498 app.local('layout', false);499503Which can then be overridden within the _res.render()_ call if need be:500Which can then be overridden within the _res.render()_ call if desired, and is otherwise functionally equivalent to passing directly to `res.render()`:501502 res.render('myview.ejs', { layout: true });503504When an alternate layout is required, we may also specify a path. For example if we have _view engine_ set to _jade_ and a file named _./views/mylayout.jade_ we can simply pass:
7 unmodified lines
512These paths may also be absolute:513514 res.render('page', { layout: __dirname + '/../../mylayout.jade' });515519A good example of this is specifying custom _ejs_ opening and closing tags:520521 app.set('view options', {522 open: '{{',523 close: '}}'524 });525516### View Partials517518The Express view system has built-in support for partials and collections, which are "mini" views representing a document fragment. For example rather than iterating519in a view to display comments, we could use partial collection:
834 unmodified lines
modified:examples/layout-control/app.js+1 added-1 removed