Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a9f140

Browse files
committed
Added globals section
1 parenta21fb26 commit3a9f140

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎components/templating/introduction.rst‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,33 @@ to render the template originally) inside the template to render another templat
7373
<?php echo $view->render('hello.php', array('firstname' => $name)) ?>
7474
<?php endforeach ?>
7575

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+
76103
Output Escaping
77104
---------------
78105

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp