mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 12:37:15 +00:00
Merge branch '1.x' into 2.x
* 1.x: Throw exception in case non-Traversable data is passed to "filter" filter Improve batch code example
This commit is contained in:
@@ -7,7 +7,7 @@ missing items:
|
||||
|
||||
.. code-block:: twig
|
||||
|
||||
{% set items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %}
|
||||
{% set items = ['a', 'b', 'c', 'd'] %}
|
||||
|
||||
<table>
|
||||
{% for row in items|batch(3, 'No item') %}
|
||||
@@ -31,11 +31,6 @@ The above example will be rendered as:
|
||||
</tr>
|
||||
<tr>
|
||||
<td>d</td>
|
||||
<td>e</td>
|
||||
<td>f</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>g</td>
|
||||
<td>No item</td>
|
||||
<td>No item</td>
|
||||
</tr>
|
||||
|
||||
@@ -1537,6 +1537,10 @@ function twig_array_column($array, $name, $index = null): array
|
||||
|
||||
function twig_array_filter($array, $arrow)
|
||||
{
|
||||
if (!twig_test_iterable($array)) {
|
||||
throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array)));
|
||||
}
|
||||
|
||||
if (\is_array($array)) {
|
||||
return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user