Merge branch '2.x' into 3.x

* 2.x:
  removed docs about overloading
  bumped version to 2.11.2-DEV
  prepared the 2.11.1 release
  bumped version to 1.42.2-DEV
  prepared the 1.42.1 release
  added a doc note
  updated CHANGELOG
This commit is contained in:
Fabien Potencier
2019-06-04 18:39:41 +02:00
3 changed files with 17 additions and 45 deletions
+11 -2
View File
@@ -17,8 +17,13 @@
* bumped minimum PHP version to 7.2
* removed PSR-0 classes
* 2.11.1 (2019-XX-XX)
* 2.11.2 (2019-XX-XX)
* n/a
* 2.11.1 (2019-06-04)
* added support for "Twig\Markup" instances in the "in" test (again)
* allowed string operators as variables names in assignments
* fixed support for macros defined in parent templates
@@ -263,7 +268,11 @@
* improved the performance of the filesystem loader
* removed features that were deprecated in 1.x
* 1.42.1 (2019-XX-XX)
* 1.42.2 (2019-XX-XX)
* n/a
* 1.42.1 (2019-06-04)
* added support for "Twig\Markup" instances in the "in" test (again)
* allowed string operators as variables names in assignments
-43
View File
@@ -855,49 +855,6 @@ It is now possible to move the runtime logic to a new
}
}
Overloading
-----------
To overload an already defined filter, test, operator, global variable, or
function, re-define it in an extension and register it **as late as
possible** (order matters)::
class MyCoreExtension extends \Twig\Extension\AbstractExtension
{
public function getFilters()
{
return [
new \Twig\TwigFilter('date', [$this, 'dateFilter']),
];
}
public function dateFilter($timestamp, $format = 'F j, Y H:i')
{
// do something different from the built-in date filter
}
}
$twig = new \Twig\Environment($loader);
$twig->addExtension(new MyCoreExtension());
Here, we have overloaded the built-in ``date`` filter with a custom one.
If you do the same on the ``\Twig\Environment`` itself, beware that it takes
precedence over any other registered extensions::
$twig = new \Twig\Environment($loader);
$twig->addFilter(new \Twig\TwigFilter('date', function ($timestamp, $format = 'F j, Y H:i') {
// do something different from the built-in date filter
}));
// the date filter will come from the above registration, not
// from the registered extension below
$twig->addExtension(new MyCoreExtension());
.. caution::
Note that overloading the built-in Twig elements is not recommended as it
might be confusing.
Testing an Extension
--------------------
+6
View File
@@ -105,6 +105,12 @@ When calling ``import`` or ``from`` from a ``macro`` tag, the imported macros
are only defined in the current macro and they override macros defined at the
template level with the same names.
.. note::
Before Twig 2.11, it was possible to use macros imported in a block in a
"sub-block". When upgrading to 2.11, you need to either move the import in
the global scope or reimport the macros explicitly in the "sub-blocks".
Checking if a Macro is defined
------------------------------