From d18f19a3bbe764218f391932464e841b3f554c73 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sat, 3 May 2014 00:13:06 +0200 Subject: [PATCH] [ticket/12382] Allow nested loops in included files. They have to reference the fully qualified loop name in BEGIN and END. PHPBB3-12382 --- phpBB/phpbb/template/twig/lexer.php | 15 +++++++++++---- .../all/template/event/test_event_subloop.html | 4 ++-- tests/template/template_events_test.php | 1 - 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index f4efc58540..49577f6e95 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -191,9 +191,16 @@ class lexer extends \Twig_Lexer $parent_class = $this; $callback = function ($matches) use ($parent_class, $parent_nodes) { - $name = $matches[1]; - $subset = trim(substr($matches[2], 1, -1)); // Remove parenthesis - $body = $matches[3]; + $hard_parents = explode('.', $matches[1]); + array_pop($hard_parents); // ends with . + if ($hard_parents) + { + $parent_nodes = array_merge($hard_parents, $parent_nodes); + } + + $name = $matches[2]; + $subset = trim(substr($matches[3], 1, -1)); // Remove parenthesis + $body = $matches[4]; // Replace $body = str_replace('', '{% else %}', $body); @@ -242,7 +249,7 @@ class lexer extends \Twig_Lexer return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}"; }; - return preg_replace_callback('#(.+?)#s', $callback, $code); + return preg_replace_callback('#(.+?)#s', $callback, $code); } /** diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html index 4fdba859f3..98fa1770ba 100644 --- a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html +++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html @@ -1,2 +1,2 @@ -[{event_loop.S_ROW_COUNT}[subloop:{event_loop.subloop.S_ROW_COUNT}] -] +[{event_loop.S_ROW_COUNT}[subloop:{event_loop.subloop.S_ROW_COUNT}] +] diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index d09f22944f..866d42d831 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -102,7 +102,6 @@ Zeta test event in all', ), array(), 'event_loop[0[subloop:0]]', - 'Event files are missing opened parent loops: PHPBB3-12382', ), ); }