From d58ac9a1a8b2de91c2679c06e1d56b85508c841c Mon Sep 17 00:00:00 2001 From: Lorenz Date: Tue, 7 Jan 2025 18:45:57 +0100 Subject: [PATCH] docs and changelog --- CHANGELOG | 1 + doc/filters/invoke.rst | 19 +++++++++++++++++++ doc/templates.rst | 6 ++++++ 3 files changed, 26 insertions(+) create mode 100644 doc/filters/invoke.rst diff --git a/CHANGELOG b/CHANGELOG index f1d757d20..5b01ea7ff 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ # 3.19.0 (2025-XX-XX) + * Add the `invoke` filter * Make `{}` optional for the `types` tag * Add `LastModifiedExtensionInterface` and implementation in `AbstractExtension` to track modification of runtime classes diff --git a/doc/filters/invoke.rst b/doc/filters/invoke.rst new file mode 100644 index 000000000..63db1c6aa --- /dev/null +++ b/doc/filters/invoke.rst @@ -0,0 +1,19 @@ +``invoke`` +======= + +The ``invoke`` filter invokes an arrow function with the the given arguments: + +.. code-block:: twig + + {% set person = {first: "Bob", last: "Smith"} %} + {% set func = p => "#{p.first} #{p.last}" %} + + {{ func|invoke(person) }} + {# outputs Bob Smith #} + +Note that the arrow function has access to the current context. + +Arguments +--------- + +All given arguments are passed to the arrow function diff --git a/doc/templates.rst b/doc/templates.rst index 3c9a5d134..fc5a4d087 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -1018,6 +1018,12 @@ The following operators don't fit into any of the other categories: Arrow function support for functions, macros, and method calls was added in Twig 3.15 (filters and tests were already supported). + Arrow functions can be invoked using the ``invoke`` filter. + + .. versionadded:: 3.19 + + The ``invoke`` filter has been added in Twig 3.19. + Operators ~~~~~~~~~