From 50f5271ef06f5945e227f1db3b5dad5cde94ff9a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 22 Feb 2013 15:46:46 +0100 Subject: [PATCH] Ceil the size in batch filter --- lib/Twig/Extension/Core.php | 2 + test/Twig/Tests/Fixtures/filters/batch.test | 33 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index a856b59..785b56b 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -1324,6 +1324,8 @@ function twig_array_batch($items, $size, $fill = null) $items = iterator_to_array($items, false); } + $size = ceil($size); + $result = array_chunk($items, $size, true); if (null !== $fill) { diff --git a/test/Twig/Tests/Fixtures/filters/batch.test b/test/Twig/Tests/Fixtures/filters/batch.test index af996f2..0d3f035 100644 --- a/test/Twig/Tests/Fixtures/filters/batch.test +++ b/test/Twig/Tests/Fixtures/filters/batch.test @@ -10,6 +10,16 @@ {% endfor %} + + +{% for row in items|batch(2.1, '') %} + + {% for column in row %} + + {% endfor %} + +{% endfor %} +
{{ column }}
--DATA-- return array('items' => array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j')) --EXPECT-- @@ -35,3 +45,26 @@ return array('items' => array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j')) + + + + + + + + + + + + + + + + + + + + + + +
abc
def
ghi
j
-- 1.7.2.5