Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global view context. #2100

Merged
merged 2 commits into from Nov 7, 2014
Merged

Global view context. #2100

merged 2 commits into from Nov 7, 2014

Conversation

@jagoda
Copy link
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 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 issue Nov 7, 2014
@hueniverse hueniverse merged commit 09bfbc5 into hapijs:master Nov 7, 2014
1 check passed
@lock
Copy link

@lock 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.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants