Skip to content

Global view context.#2100

Merged
hueniverse merged 2 commits intohapijs:masterfrom
jagoda:feat-update-vision
Nov 7, 2014
Merged

Global view context.#2100
hueniverse merged 2 commits intohapijs:masterfrom
jagoda:feat-update-vision

Conversation

@jagoda
Copy link
Copy Markdown
Contributor

@jagoda jagoda commented Nov 5, 2014

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: <timewhencontextruns>,
    test: 'This is the index view.',
    type: 'local'
}

@hueniverse hueniverse added dependency Update module dependency feature New functionality or improvement labels Nov 6, 2014
@hueniverse hueniverse added this to the 7.3.1 milestone Nov 6, 2014
@hueniverse hueniverse self-assigned this Nov 6, 2014
hueniverse pushed a commit that referenced this pull request Nov 7, 2014
@hueniverse hueniverse merged commit 09bfbc5 into hapijs:master Nov 7, 2014
@lock
Copy link
Copy Markdown

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

dependency Update module dependency feature New functionality or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants