Skip to content

Instantly share code, notes, and snippets.

@serapheem
Created July 21, 2013 04:54
Show Gist options
  • Select an option

  • Save serapheem/6047528 to your computer and use it in GitHub Desktop.

Select an option

Save serapheem/6047528 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