From ea6759e332a0d7ebc0b2bbe0a15ec7b329317b13 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 4 Sep 2020 18:35:31 -0400 Subject: [PATCH] Handle collections. Fixes issue introduced in 6d361454 --- src/View/Antlers/Parser.php | 4 ++++ tests/View/Antlers/ParserTest.php | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/View/Antlers/Parser.php b/src/View/Antlers/Parser.php index c41d2238d3..cef54dfa1f 100644 --- a/src/View/Antlers/Parser.php +++ b/src/View/Antlers/Parser.php @@ -595,6 +595,10 @@ public function parseCallbackTags($text, $data) } if (! empty($values)) { + if ($values instanceof Collection) { + $values = $values->all(); + } + if (Arr::isAssoc($values)) { $replacement = $this->parse($content, array_merge($data, $values)); } else { diff --git a/tests/View/Antlers/ParserTest.php b/tests/View/Antlers/ParserTest.php index dfdfc028cd..06d54b7b0c 100644 --- a/tests/View/Antlers/ParserTest.php +++ b/tests/View/Antlers/ParserTest.php @@ -521,6 +521,15 @@ public function testArrayModifiersGetParsed() $this->assertEquals('one', $this->parse($template, $this->variables)); } + public function testArrayModifiersOnCollectionsGetParsed() + { + $template = '{{ simple limit="1" }}{{ value }}{{ /simple }}'; + + $this->assertEquals('one', $this->parse($template, [ + 'simple' => collect(['one', 'two', 'three']), + ])); + } + public function testRecursiveChildren() { // the variables are inside RecursiveChildren@index