Cookbook

Injecting variables into all templates (i.e. Global Variables)

As exemplified in the Symfony Cookbook it is possible to make a variable to be accessible to all the templates you use by configuring your app/config/config.yml file:

app/config/config.yml
dwoo:
    # ...
    globals:
        ga_tracking: UA-xxxxx-x

Now, the variable ga_tracking is available in all Dwoo templates:

<p>Our google tracking code is: {$ga_tracking} </p>

How to Access the User, Request, Session & more via the app Variable

During each request, Symfony will set a global template variable app available in both Twig and PHP template engines by default.
Dwoo SymfonyBundle add the same global variable to be accessible from all templates.
The app variable is a GlobalVariables instance which will give you access to some application specific variables automatically.

Like the Twig implementation you can access to this variables like:

Twig syntax Dwoo syntax
{{ app.user }} {$app->getUser()}
{{ app.request }} {$app->getRequest()}
{{ app.session }} {$app->getSession()}
{{ app.environment }} {$app->getEnvironment()}
{{ app.debug }} {$app->getDebug()}
{{ app.token }} {$app->getToken()}
<p>Username: {$app->getUser()->getUsername()}</p>
{if $app->getDebug()}
    <p>Request method: {$app->getRequest()->getMethod()}</p>
    <p>Application Environment: {$app->getEnvironment()}</p>
{/if}

Enable WebProfile

app/config/config.yml
dwoo:
    # ...
    web_profiler: '%kernel.debug%'