Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 with 23 additions and 7 deletions.
  1. +11 −1 README.md
  2. +12 −6 lib/hbs.js
12 README.md
View
@@ -47,7 +47,7 @@ To define block content in a page.
CONTENT HERE
{{/contentFor}}
-There are three ways to use a layout
+There are three ways to use a layout, listed in the order in which they are checked for and used:
1. Declarative within a page. Use handlebars comment. `LAYOUT` is a relative path from template.
@@ -60,6 +60,16 @@ There are three ways to use a layout
veggies: veggies,
layout: 'layout/veggie'
});
+
+ This option also allows for default layout suppression by passing in a falsey Javascript value as the value of the `layout` property:
+
+```
+ res.render('veggies', {
+ title: 'My favorite veggies',
+ veggies: veggies,
+ layout: null // render without using a layout template
+ });
+```
3. Lastly, use `defaultLayout` if specified in hbs configuration options.
18 lib/hbs.js
View
@@ -272,12 +272,18 @@ var _express3 = function(filename, options, cb) {
}
// 2. Layout specified by options from render
- else if (options.layout) {
- var layoutFile = path.resolve(path.join(path.dirname(filename), options.layout));
- cacheLayout(layoutFile, options.cache, function(err, layoutTemplate) {
- if (err) return cb(err);
- renderIt(layoutTemplate);
- });
+ else if (typeof(options.layout) !== 'undefined') {
+ if (options.layout) {
+ var layoutFile = path.resolve(path.join(path.dirname(filename), options.layout));
+ cacheLayout(layoutFile, options.cache, function(err, layoutTemplate) {
+ if (err) return cb(err);
+ renderIt(layoutTemplate);
+ });
+
+ } else {
+ // if the value is falsey, behave as if no layout should be used - suppress defaults
+ renderIt(null);
+ }
}
// 3. Default layout specified when middleware was configured.
Please sign in to comment.
Something went wrong with that request. Please try again.