@@ -871,6 +871,37 @@ is by default "web").
871
871
The end result is a page that includes both the ``main.css `` and ``contact.css ``
872
872
stylesheets.
873
873
874
+ The ``app `` Global Variable
875
+ ---------------------------
876
+
877
+ Symfony2 will set a global template variable ``app `` on every request in
878
+ both Twig and PHP template engines by default. The ``app `` variable will
879
+ give you access to some application specific variables automatically:
880
+
881
+ * ``app.security `` - The security context service.
882
+ * ``app.user `` - The current user object. Equivalent to ``app.security.token.user ``.
883
+ * ``app.request `` - The request object.
884
+ * ``app.session `` - The session object. Equivalent to ``app.request.session ``.
885
+ * ``app.environment `` - The current environment (dev, prod, etc)
886
+ * ``app.debug `` - True if in debug mode. False otherwise.
887
+
888
+ .. configuration-block ::
889
+
890
+ .. code-block :: html+jinja
891
+
892
+ {% if app.debug %}
893
+ <p>Username: {{ app.user.username }}</p>
894
+ <p>Request method: {{ app.request.method }}</p>
895
+ <p>Application Environment: {{ app.environment }}</p>
896
+ {% endif %}
897
+
898
+ .. code-block :: html+php
899
+ <?php if ($app->getDebug()): ?>
900
+ <p>Username: <?php echo $app->getUser()->getUsername() ?></p>
901
+ <p>Request method: <?php echo $app->getRequest()->getMethod() ?></p>
902
+ <p>Application Environment: <?php echo $app->getEnvironment() ?></p>
903
+ <?php endif; ?>
904
+
874
905
.. index ::
875
906
single: Templating; The templating service
876
907
0 commit comments