This PR was submitted for the 2.x branch but it was merged into the 1.x branch instead (closes#3024).
Discussion
----------
doc(filter): add example of `filter` without `for` use
First, thanks for #2996! :)
This PR add an example of `filter` usage without using a `for` loop, to prevend some misinterpretation to people.
At first read, I thought `filter` was only usable with `for` loop, but nope. In fact it iterates on the result produced by `filter`.
Commits
-------
847276a6 doc(filter): add example of `filter` without `for` use
This PR was merged into the 1.x branch.
Discussion
----------
Fix the "filter" filter when the argument is \Traversable but does not implement \Iterator
close#3015, closes#3016
Commits
-------
c2f685e1 fixed the "filter" filter when the argument is \Traversable but does not implement \Iterator
This PR was submitted for the 2.x branch but it was merged into the 1.x branch instead (closes#3006).
Discussion
----------
update docs for for loop with conditional to reference filter filters
I don't know if there needs to be the same emphasis for this case as there's no special syntax for this any more? This PR assumes the same emphasis.
Commits
-------
b905e023 update docs for for loop with conditional to reference filter filters
This PR was merged into the 1.x branch.
Discussion
----------
Fix a PHP fatal error when calling a macro imported in the template in a nested block
Commits
-------
11353ce3 fixed a PHP fatal error when calling a macro imported in the template in a nested block
This PR was merged into the 1.x branch.
Discussion
----------
Tweak the error message when using extends in a block/macro
Commits
-------
70c1b3a2 tweaked the error message when using extends in a block/macro
This PR was merged into the 1.x branch.
Discussion
----------
Fix a PHP fatal error when calling a macro, imported in the template, in another macro
The current code iterates over all imported functions (traversing all the scopes). So, the macro was found at compilation time, but didn't work at runtime, leading to a PHP fatal error. Now, you get a proper exception at compilation time.
Commits
-------
ba9b9681 fixed a PHP fatal error when calling a macro, imported in the template, in another macro
This PR was merged into the 1.x branch.
Discussion
----------
Fix wrong error message on "import" and "from"
Commits
-------
118462c1 fixed wrong error message on "import" and "from"
This PR was merged into the 1.x branch.
Discussion
----------
Correct Twig_SimpleFilter, Twig_SimpleFunction, Twig_SimpleTest deprecation doc
Reverts https://github.com/twigphp/Twig/commit/3632a46e82fbb391b0fc72674bd8946e0b7c5bf7 for deprecated.rst
Commits
-------
65047482 Correct Twig_SimpleFilter/Twig_SimpleFunction/Twig_SimpleTest deprecation doc (Revert: moved to namespaced classes by default)
This PR was squashed before being merged into the 1.x branch (closes#3004).
Discussion
----------
Fix support for PHP 7.4
Commits
-------
f958bd1e fixed deprecation under PHP 7.4
1fb0f970 fixed PHP 7.4 support
7be8e944 added PHP 7.4 in Travis config
This PR was merged into the 1.x branch.
Discussion
----------
Fix support for IteratorAggregate in the filter filter
Commits
-------
084be27d fixed support for IteratorAggregate in the filter filter
This PR was squashed before being merged into the 1.x branch (closes#2996).
Discussion
----------
Add "filter", "map", and "reduce" filters
This PR adds support for 3 new filters: `filter`, `map`, and `reduce`. They take an arrow function as an argument (a PHP closure).
I have restricted the usage of arrow functions as much as possible as it makes no sense to support them everywhere. So, for now, they are only accepted as arguments to filters (using them as arguments to function is not supported but could be easily added if we have a use case).
The syntax is the following: `(x) => x + 3` where `(x)` is the list of arguments, `=>` starts the body, and the body is any Twig expression. Within the arrow function, the context is also available: `(x) => x + offset` works if `offset` is defined in the current context.
~~These new filters will allow us to deprecate the `if` support on the `for` tag, which does not work well with the `loop` variable:~~
```twig
{% set sizes = {xs: 34, s: 36, m: 38, l: 40, xl: 42} %}
{# before #}
{% for name, size in sizes if size < 38 %}
{{ name }} = {{ size }}
{% loop.last ? 'LAST' %} {# <--- works with this PR #}
{% endfor %}
{# after #}
{% for name, size in sizes|filter(size => size < 38) %}
{{ name }} = {{ size }}
{{ loop.last ? 'LAST' }}
{% endfor %}
```
This closes#2785
Commits
-------
5c15f897 added the key to the map and filter filters
13274bbf added support for iterators
175041e0 removed fn in front of arrow functions
dc277635 changed arrow syntax
b30bce11 added "filter", "map", and "reduce" filters
This PR was merged into the 1.x branch.
Discussion
----------
Fix partial output leak when a PHP fatal error occurs
closes#1962 (thank you @fluff for the "trick")
Commits
-------
6196fe5b fixed partial output leak when a PHP fatal error occurs