diff --git a/Readme.md b/Readme.md index 092c5da..a2fd15b 100644 --- a/Readme.md +++ b/Readme.md @@ -35,6 +35,23 @@ hbs.registerHelper('helper_name', function(...) { ... }); hbs.registerPartial('partial_name', 'partial value'); ``` +For convenience, `registerPartials` provides a quick way to load all partials from a specific directory: + +```javascript +var hbs = require('hbs'); + +hbs.registerPartials(__dirname + '/views/partials'); +``` + +Partials that are loaded from a directory are named based on their filename, where spaces and hyphens are replaced with an underscore character: + +``` +template.html -> {{> template}} +template 2.html -> {{> template_2}} +login view.hbs -> {{> login_view}} +template-file.html -> {{> template_file}} +``` + See the [handlebars.js](http://github.com/wycats/handlebars.js) README and docs for more information. ## handlebars ## diff --git a/examples/partial/app.js b/examples/partial/app.js index fcfde76..b6b606d 100644 --- a/examples/partial/app.js +++ b/examples/partial/app.js @@ -9,6 +9,7 @@ var hbs = require('hbs'); var app = express(); hbs.registerPartial('partial', fs.readFileSync(__dirname + '/views/partial.hbs', 'utf8')); +hbs.registerPartials(__dirname + '/views/partials'); // set the view engine to use handlebars app.set('view engine', 'hbs'); diff --git a/examples/partial/views/index.hbs b/examples/partial/views/index.hbs index 158577c..915cb92 100644 --- a/examples/partial/views/index.hbs +++ b/examples/partial/views/index.hbs @@ -5,3 +5,8 @@ regular body {{> partial}} +{{> partial1}} +{{> partial2}} +{{> partial3}} +{{> partial4}} +{{> partial5}} diff --git a/examples/partial/views/layout.hbs b/examples/partial/views/layout.hbs index 36db91e..73bbc7e 100644 --- a/examples/partial/views/layout.hbs +++ b/examples/partial/views/layout.hbs @@ -12,6 +12,7 @@ post body