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

Added pass method to pipeline variables into Javascript #6

Open
wants to merge 1 commit into
base: 1.2/develop
Choose a base branch
from

Conversation

rafi
Copy link

@rafi rafi commented May 22, 2013

You can pipeline server-side information into client-side Javascript variables using the pass method:

$this->assets->pass([
        'route' => [
            'name'       => Route::name($this->request->route()),
            'controller' => strtolower($this->request->controller()),
            'action'     => $this->request->action()
        ],
        'url' => [
            'base'  => URL::base(),
            'media' => URL::base().Media::uri('/').'/'
        ],
        'environment' => Kohana::$environment
    ]);

When you use Assets::get() to retrieve all the head assets, data will be encoded like this:

<script type="text/javascript">window.pass = { "route": { "name": "default", "controller": "Welcome", "action": "index" }, "url": { "base": "/", "media": "/media/kohana/" }, "environment": 40 };</script>

In Javascript, your variables are set and ready to use within the window.pass global variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant