From 3f8a67fd9d341ac27d216c75824795a0f3559450 Mon Sep 17 00:00:00 2001 From: Eugene Leonovich Date: Fri, 15 Jul 2022 00:44:08 +0200 Subject: [PATCH] Fix "Undefined variable $macros" when using filter in a deferred block (#14) See https://github.com/rybakit/twig-deferred-extension/issues/13. --- src/DeferredBlockNode.php | 1 + tests/Fixtures/filter.test | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/Fixtures/filter.test diff --git a/src/DeferredBlockNode.php b/src/DeferredBlockNode.php index 6ae974f..2ba595f 100755 --- a/src/DeferredBlockNode.php +++ b/src/DeferredBlockNode.php @@ -34,6 +34,7 @@ public function compile(Compiler $compiler) : void ->addDebugInfo($this) ->write("public function block_{$name}_deferred(\$context, array \$blocks = [])\n", "{\n") ->indent() + ->write("\$macros = \$this->macros;\n") ->subcompile($this->getNode('body')) ->write("\$this->deferred->resolve(\$this, \$context, \$blocks);\n") ->outdent() diff --git a/tests/Fixtures/filter.test b/tests/Fixtures/filter.test new file mode 100644 index 0000000..a586e52 --- /dev/null +++ b/tests/Fixtures/filter.test @@ -0,0 +1,10 @@ +--TEST-- +filter +--TEMPLATE-- +{% block foo deferred %} +1{% for test in test_array|default([])|filter(test => true) %}{% endfor %}2 +{% endblock %} +--DATA-- +return [] +--EXPECT-- +12