Breaking: #108148 - Disallow Fluid Variable Names With Underscore Prefix
See forge#108148
Description
With Fluid 5, it is no longer possible to define custom template variables
that start with an underscore (_). These variable names are reserved for
future internal use by Fluid itself, similarly to the already existing {_.
Impact
This change affects ViewHelpers that define new variables, such as
<f:variable>,
<f:for> or
<f:render>.
It also affects Fluid's PHP APIs, namely
$view->assign and
$view->assign.
Affected installations
Installations with Fluid templates that use custom variable names starting with
an underscore (_) will encounter exceptions when such a template is rendered.
A deprecation is written to the deprecation log since TYPO3 13.4.21 if this
is encountered in a Fluid template during rendering.
Migration
The following examples no longer work with Fluid 5:
<f:variable name="_temp" value="a temporary value" />
{_temp}
<f:for each="{myArray}" as="_item">
{_item}
</f:for>
<f:render partial="Footer" arguments="{_data: myData}" />
$view->assign('_data', $myData);
$view->assignMultiple([
'_data' => $myData,
]);
All examples would lead to the following exception:
#1756622558 TYPO3Fluid\Fluid\Core\Variables\InvalidVariableIdentifierException
Variable identifiers cannot start with a "_": _myVariable
In all cases, the variable name must be changed to no longer start with an
underscore (_).
Note that this only affects variable names, but not property names in objects or array keys that are accessed within a Fluid template. The following examples are not affected by this change:
{myArray._myKey}
{myObject._myProperty}
Also note that the existing {_ (and any further internal variables added
by Fluid) are not affected. This code will continue to work just fine:
<f:render partial="Footer" arguments="{_all}"/>