@@ -871,6 +871,45 @@ 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
+ Global Template Variables
875
+ -------------------------
876
+
877
+ During each request, Symfony2 will set a global template variable ``app ``
878
+ in both Twig and PHP template engines by default. The ``app `` variable
879
+ is a :class: `Symfony\\ Bundle\\ FrameworkBundle\\ Templating\\ GlobalVariables `
880
+ instance which will give you access to some application specific variables
881
+ automatically:
882
+
883
+ * ``app.security `` - The security context.
884
+ * ``app.user `` - The current user object.
885
+ * ``app.request `` - The request object.
886
+ * ``app.session `` - The session object.
887
+ * ``app.environment `` - The current environment (dev, prod, etc).
888
+ * ``app.debug `` - True if in debug mode. False otherwise.
889
+
890
+ .. configuration-block ::
891
+
892
+ .. code-block :: html+jinja
893
+
894
+ <p>Username: {{ app.user.username }}</p>
895
+ {% if app.debug %}
896
+ <p>Request method: {{ app.request.method }}</p>
897
+ <p>Application Environment: {{ app.environment }}</p>
898
+ {% endif %}
899
+
900
+ .. code-block :: html+php
901
+
902
+ <p>Username: <?php echo $app->getUser()->getUsername() ?></p>
903
+ <?php if ($app->getDebug()): ?>
904
+ <p>Request method: <?php echo $app->getRequest()->getMethod() ?></p>
905
+ <p>Application Environment: <?php echo $app->getEnvironment() ?></p>
906
+ <?php endif; ?>
907
+
908
+ .. tip ::
909
+
910
+ You can add your own global template variables. See the cookbook example
911
+ on :doc: `Global Variables</cookbook/templating/global_variables> `.
912
+
874
913
.. index ::
875
914
single: Templating; The templating service
876
915
0 commit comments