Skip to content

Instantly share code, notes, and snippets.

@serapheem
Created November 6, 2012 10:31
Show Gist options
  • Save serapheem/4023920 to your computer and use it in GitHub Desktop.
Save serapheem/4023920 to your computer and use it in GitHub Desktop.
Symfony2 - Global Template Variables
List:
app.security - The security context.
app.user - The current user object.
app.request - The request object.
app.session - The session object.
app.environment - The current environment (dev, prod, etc).
app.debug - True if in debug mode. False otherwise.
Twig:
<p>Username: {{ app.user.username }}</p>
{% if app.debug %}
<p>Request method: {{ app.request.method }}</p>
<p>Application Environment: {{ app.environment }}</p>
{% endif %}
PHP:
<p>Username: <?php echo $app->getUser()->getUsername() ?></p>
<?php if ($app->getDebug()): ?>
<p>Request method: <?php echo $app->getRequest()->getMethod() ?></p>
<p>Application Environment: <?php echo $app->getEnvironment() ?></p>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment