-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #4518 Add invoke filter (Lorenz, Lorenzschaef, fabpot)
This PR was merged into the 3.x branch. Discussion ---------- Add invoke filter Adds a new filter `invoke`, to invoke arrow functions and other php callables. See the discussion here: #4378 (comment) Commits ------- 3e93e91 Finish the work c4fd25f fix indentation dacbe51 Apply suggestions from code review 2b95bd6 typo 09c30c3 fix merge d58ac9a docs and changelog edecc13 typehint instead of checkArrow f271158 checkArrow, typehints 8b43275 invoke filter
- Loading branch information
Showing
5 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
``invoke`` | ||
========== | ||
|
||
.. versionadded:: 3.19 | ||
|
||
The ``invoke`` filter has been added in Twig 3.19. | ||
|
||
The ``invoke`` filter invokes an arrow function with 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 #} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
"invoke" filter | ||
--TEMPLATE-- | ||
{% set func = x => 'Hello '~x %} | ||
{{ func|invoke('World') }} | ||
{% set func2 = (x, y) => x+y %} | ||
{{ func2|invoke(3, 2) }} | ||
--DATA-- | ||
return [] | ||
--CONFIG-- | ||
return [] | ||
--EXPECT-- | ||
Hello World | ||
5 |