File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,33 @@ to render the template originally) inside the template to render another templat
73
73
<?php echo $view->render('hello.php', array('firstname' => $name)) ?>
74
74
<?php endforeach ?>
75
75
76
+ Global Variables
77
+ ----------------
78
+
79
+ Sometimes, you need to set a variable which is available in all templates
80
+ rendered by an engine (like the ``$app `` variable when using the Symfony2
81
+ framework). These variables can be set by using the
82
+ :method: `Symfony\\ Component\\ Templating\\ PhpEngine::addGlobal ` method and they
83
+ can be accessed in the template as normal variables::
84
+
85
+ $templating->addGlobal('ga_tracking', 'UA-xxxxx-x');
86
+
87
+ In a template:
88
+
89
+ .. code-block :: html+php
90
+
91
+ <p>The google tracking code is: <?php echo $ga_tracking ?></p>
92
+
93
+ .. caution ::
94
+
95
+ The global variables cannot be called ``this `` or ``view ``, since they are
96
+ already used by the PHP engine.
97
+
98
+ .. note ::
99
+
100
+ The global variables can be overriden by a local variable in the template
101
+ with the same name.
102
+
76
103
Output Escaping
77
104
---------------
78
105
You can’t perform that action at this time.
0 commit comments