https://github.com/simov/hapi-hogan
Hogan.js templating in Hapi.js
https://github.com/simov/hapi-hogan
Last synced: 8 months ago
JSON representation
Hogan.js templating in Hapi.js
- Host: GitHub
- URL: https://github.com/simov/hapi-hogan
- Owner: simov
- License: mit
- Created: 2015-02-21T12:51:16.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-08-28T06:37:49.000Z (over 10 years ago)
- Last Synced: 2025-05-07T10:41:34.612Z (8 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-hogan
```js
var Hapi = require('hapi')
, hogan = require('hapi-hogan')
server = new Hapi.Server()
server.connection({host:'localhost', port:3000})
server.route({method:'GET', path:'/', handler:function (req, res) {
res.view('layout', {name:'simo', partials: {header:'header'}})
}
})
server.views({
relativeTo:__dirname,
path:'./views',
engines: {
html:{
module: hogan,
compileMode: 'sync',
compileOptions: {
partialsPath: path.join(__dirname, 'partials'),
isCached: true
}
}
}
})
server.start()
```
Just like in [consolidate][consolidate] pass your partials using the `partials` key
```js
server.route({method:'GET', path:'/', handler:function (req, res) {
res.view('layout', {name:'simo', partials: {header:'header'}})
}
})
```
Here `header` is the name of your `{{>header}}` partial and the 'header' string is the relative path to it. In the above example thats the `header.html` file located in the `partials` folder
```js
server.views({
relativeTo:__dirname,
path:'./views',
engines: {
html:{
module: hogan,
compileMode: 'sync',
compileOptions: {
partialsPath: path.join(__dirname, 'partials'),
isCached: true
}
}
}
})
```
`partialsPath` is the absolute path to your partials folder. The partials are cached by default, to disable it set `isCached` to `false`. Both of these two options should be placed inside the `compileOptions` key
[consolidate]: https://github.com/tj/consolidate.js