hapijs/hapi — pull request #2100 by jagoda (2014-11-05 23:28:35+00:00)
Title: Global view context.

Updates `vision` to version `1.2.0` in order to provide the ability to specify a global view context that is merged with any context values specified on the handler or via `reply.view()`. When merging, the global context values always have lower precedence than other context values. The global value may be either a context object or a function that takes no arguments and returns a context object. If a function is provided, it will be evaluated on each request before merging with other context values.
- - -
Specifying
```
server.views({
context: {
version: '1.5.5',
name: 'Application Name',
type: 'global'
}
});
```
and then calling
```
reply.view('index', {
test: 'This is the index view.',
type: 'local'
});
```
results in a context object of
```
{
version: '1.5.5',
name: 'Application name',
test: 'This is the index view.',
type: 'local'
}
```
- - -
Specifying
```
server.views({
context: function () {
return {
version: '1.4.5',
date: Date.now(),
type: 'global'
};
}
});
```
and then calling
```
reply.view('index', {
test: 'This is the index view.',
type: 'local'
});
```
results in a context object of
```
{
version: '1.4.5',
date: ,
test: 'This is the index view.',
type: 'local'
}
```