.. include:: /Includes.rst.txt .. _variables: ========= Variables ========= Assign a variable in PHP: .. code-block:: php $this->view->assign('title', 'An example title'); Output it in a Fluid template: .. code-block:: html

{title}

The result: .. code-block:: html

An example title

In the template's HTML code, wrap the variable name into curly braces to output it. .. _variable-all: Special _all Variable ========================= The special variable `{_all}` contains an array with all variables that are currently defined in your template. This can be helpful for debugging purposes, but also if you want to pass all variables to a partial: .. code-block:: xml However, be advised that this makes it more difficult to re-use partials, so it's recommend to only pass the variables that are actually needed in the partial. .. _variable-scopes: Variable Scopes =============== Each Fluid template, partial and section has its own variable scope. For templates, these variables are set via the PHP API, for partials and sections the `` ViewHelper has a `arguments` argument to provide variables. Inside templates, partials and sections there are two variable scopes: global variables and local variables. Local variables are created by ViewHelpers that provide additional variables to their child nodes. Local variables are only valid in their appropriate context and don't leak out to the whole template. For example, `` and `` create local variables: .. code-block:: xml If a global variable uses the same name as a local value, the state of the global value will be restored when the local variable is invalidated: .. code-block:: xml If a variable is created in a local block, for example by using the `` ViewHelper, that variable is treated as a global variable, so it will leak out of the scope: .. code-block:: xml If a global variable is created inside a local scope and uses the same name as a local variable, it will still leak out of the scope and will also be valid inside the scope: .. code-block:: xml