Allow macro calls and definition inside cache tag

This commit is contained in:
Yann ROTROU
2021-01-11 18:30:42 +01:00
parent 2179df17ee
commit 0bdad6fbdc
2 changed files with 23 additions and 1 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ class CacheNode extends Node
->addDebugInfo($this)
->write('$cached = $this->env->getRuntime(\'Twig\Extra\Cache\CacheRuntime\')->getCache()->get(')
->subcompile($this->getNode('key'))
->raw(", function (\Symfony\Contracts\Cache\ItemInterface \$item) use (\$context) {\n")
->raw(", function (\Symfony\Contracts\Cache\ItemInterface \$item) use (\$context, \$macros) {\n")
->indent()
;
@@ -0,0 +1,22 @@
--TEST--
macro call inside "cache" tag
--TEMPLATE--
{% macro macro_out(bar) %}{{ bar }}{% endmacro %}
1
{% cache "testmacro1" ttl(3) %}
{%~ macro macro_in(bar) %}{{ bar }}{% endmacro %}
2
{{ _self.macro_out(3) }}
{{ _self.macro_in(4) }}
{% endcache %}
5
{{ _self.macro_in(6) }}
--DATA--
return []
--EXPECT--
1
2
3
4
5
6