Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #9 from ivanstojic/master

Suppressing default layout from a render call
  • Loading branch information...
commit 9708358ed3e4a4261b94fc6e4fd7f8186c1aa441 2 parents 5d7b802 + 83c6852
Mario Gutierrez mgutz authored

Showing 2 changed files with 23 additions and 7 deletions. Show diff stats Hide diff stats

  1. +11 1 README.md
  2. +12 6 lib/hbs.js
12 README.md
Source Rendered
@@ -47,7 +47,7 @@ To define block content in a page.
47 47 CONTENT HERE
48 48 {{/contentFor}}
49 49
50   -There are three ways to use a layout
  50 +There are three ways to use a layout, listed in the order in which they are checked for and used:
51 51
52 52 1. Declarative within a page. Use handlebars comment. `LAYOUT` is a relative path from template.
53 53
@@ -60,6 +60,16 @@ There are three ways to use a layout
60 60 veggies: veggies,
61 61 layout: 'layout/veggie'
62 62 });
  63 +
  64 + This option also allows for default layout suppression by passing in a falsey Javascript value as the value of the `layout` property:
  65 +
  66 +```
  67 + res.render('veggies', {
  68 + title: 'My favorite veggies',
  69 + veggies: veggies,
  70 + layout: null // render without using a layout template
  71 + });
  72 +```
63 73
64 74 3. Lastly, use `defaultLayout` if specified in hbs configuration options.
65 75
18 lib/hbs.js
@@ -272,12 +272,18 @@ var _express3 = function(filename, options, cb) {
272 272 }
273 273
274 274 // 2. Layout specified by options from render
275   - else if (options.layout) {
276   - var layoutFile = path.resolve(path.join(path.dirname(filename), options.layout));
277   - cacheLayout(layoutFile, options.cache, function(err, layoutTemplate) {
278   - if (err) return cb(err);
279   - renderIt(layoutTemplate);
280   - });
  275 + else if (typeof(options.layout) !== 'undefined') {
  276 + if (options.layout) {
  277 + var layoutFile = path.resolve(path.join(path.dirname(filename), options.layout));
  278 + cacheLayout(layoutFile, options.cache, function(err, layoutTemplate) {
  279 + if (err) return cb(err);
  280 + renderIt(layoutTemplate);
  281 + });
  282 +
  283 + } else {
  284 + // if the value is falsey, behave as if no layout should be used - suppress defaults
  285 + renderIt(null);
  286 + }
281 287 }
282 288
283 289 // 3. Default layout specified when middleware was configured.

0 comments on commit 9708358

Please sign in to comment.
Something went wrong with that request. Please try again.