mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-08 16:36:58 +00:00
fixed the filter filter
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 2.11.3 (2019-XX-XX)
|
||||
|
||||
* fixed the filter filter (allow the result to be used several times)
|
||||
* fixed macro auto-import when a template contains only macros
|
||||
|
||||
* 2.11.2 (2019-06-05)
|
||||
|
||||
@@ -1522,11 +1522,12 @@ function twig_array_column($array, $name): array
|
||||
|
||||
function twig_array_filter($array, $arrow)
|
||||
{
|
||||
foreach ($array as $k => $v) {
|
||||
if ($arrow($v, $k)) {
|
||||
yield $k => $v;
|
||||
}
|
||||
if (\is_array($array)) {
|
||||
return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH);
|
||||
}
|
||||
|
||||
// the IteratorIterator wrapping is needed as some internal PHP classes are \Traversable but do not implement \Iterator
|
||||
return new \CallbackFilterIterator(new \IteratorIterator($array), $arrow);
|
||||
}
|
||||
|
||||
function twig_array_map($array, $arrow)
|
||||
|
||||
@@ -35,6 +35,11 @@
|
||||
{% for k, v in xml|filter(x => true) %}
|
||||
{{ k }}/{{ v }}
|
||||
{% endfor %}
|
||||
|
||||
{% set coll = ['a', 'b']|filter(v => v is same as('a')) %}
|
||||
{% if coll|length > 0 %}
|
||||
{{- coll|join(', ') }}
|
||||
{% endif %}
|
||||
--DATA--
|
||||
return [
|
||||
'it' => new \ArrayIterator(['a' => 1, 'b' => 2, 'c' => 5, 'd' => 8]),
|
||||
@@ -68,3 +73,5 @@ elem/baz
|
||||
elem/foo
|
||||
elem/bar
|
||||
elem/baz
|
||||
|
||||
a
|
||||
|
||||
Reference in New Issue
Block a user