bug #3469 Allow macro calls and definition inside cache tag (Yann ROTROU)

This PR was merged into the 3.x branch.

Discussion
----------

Allow macro calls and definition inside cache tag

Solve #3466

Commits
-------

0bdad6fb Allow macro calls and definition inside cache tag
This commit is contained in:
Fabien Potencier
2021-01-12 13:18:26 +01:00
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