Skip to content

Commit

Permalink
document options
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario L Gutierrez committed Oct 22, 2012
1 parent f5468e8 commit 3842c19
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,35 @@ To use with express 3.
```javascript
var hbs = require('express-hbs');

// Hook in express-hbs and tell it to use hbs for extensions and use `views/partials`
// for partials.
// Hook in express-hbs and tell it to use hbs for extensions and find partials
// in `views/partials`.
app.engine('hbs', hbs.express3({partialsDir: __dirname + '/views/partials'}));
app.set('view engine', 'hbs');
app.set('views', __dirname + '/views');
```

## Syntax

To mark where page should be inserted into a layout.
Options for `#express3`

hbs.express3({
partialsDir: "{String} Path to partials templates",
extname: "{String} Extension for templates, defaults to `.hbs`",
handlebars: "{Module} Use external handlebars instead of express-hbs dependency"
});

Partials may use any extension; better for syntax highlighting.


To mark where layout should insert pag,

{{{body}}}

To use a layout, use handlebars comment. `LAYOUT` is a relative path from template.
To declare the layout for a page, use handlebars comment. `LAYOUT` is a relative path from template.

{{!< LAYOUT}}

To define a block in layout.
To define a block placeholder in layout.

{{{block "pageScripts"}}}

Expand All @@ -41,10 +52,9 @@ To define block content in a page.

## Example


File `views/layout/default.hbs`

```html
```
<html>
<head>
<title>{{title}}</title>
Expand All @@ -64,7 +74,7 @@ File `views/layout/default.hbs`

File `views/index.hbs`

```html
```
{{!< layout/default}}
{{#contentFor 'pageStyles'}}
Expand All @@ -80,10 +90,15 @@ File `views/index.hbs`
<p class='clicker'>Click me!</p>
```

To run example project

npm install -d
node example/app.js


## Credits

Some source from [donpark/hbs](https://github.com/donpark/hbs)
Inspiration and code from [donpark/hbs](https://github.com/donpark/hbs)


## License
Expand Down
13 changes: 7 additions & 6 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ app.engine('hbs', hbs.express3({partialsDir: __dirname + '/views/partials'}));
app.set('view engine', 'hbs');
app.set('views', __dirname + '/views');

var fruits = [];
fruits.push({ name: 'apple' });
fruits.push({ name: 'orange' });
fruits.push({ name: 'pear' });
var fruits = [
{name: 'apple'},
{name: 'orange'},
{name: 'pear'}
];

app.get('/', function(req, res){
app.get('/', function(req, res) {
res.render('index', {
title: 'express-hbs example'
});
});

app.get('/fruits', function(req, res){
app.get('/fruits', function(req, res) {
res.render('fruits/index', {
title: 'My favorite fruits',
fruits: fruits
Expand Down

0 comments on commit 3842c19

Please sign in to comment.