diff options
-rw-r--r-- | phpBB/phpbb/template/twig/lexer.php | 9 | ||||
-rw-r--r-- | tests/template/template_test.php | 7 | ||||
-rw-r--r-- | tests/template/templates/if.html | 2 |
3 files changed, 15 insertions, 3 deletions
diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 3534311b7a..a33de70d69 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -219,6 +219,12 @@ class phpbb_template_twig_lexer extends Twig_Lexer */ protected function fix_if_tokens($code) { + // Replace ELSE IF with ELSEIF + $code = preg_replace('#<!-- ELSE IF (.+?) -->#', '<!-- ELSEIF $1 -->', $code); + + // Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces) + $code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code); + $callback = function($matches) { $inner = $matches[2]; @@ -234,9 +240,6 @@ class phpbb_template_twig_lexer extends Twig_Lexer return "<!-- {$matches[1]}IF{$inner}-->"; }; - // Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces) - $code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code); - return preg_replace_callback('#<!-- (ELSE)?IF((.*)[\s][\$|\.|!]([^\s]+)(.*))-->#', $callback, $code); } diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 15d75f09af..38eb072df8 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -64,6 +64,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case ), array( 'if.html', + array('S_OTHER_OTHER_VALUE' => true), + array(), + array(), + '|S_OTHER_OTHER_VALUE|!false', + ), + array( + 'if.html', array('S_VALUE' => false, 'S_OTHER_VALUE' => true), array(), array(), diff --git a/tests/template/templates/if.html b/tests/template/templates/if.html index c010aff7fa..f6ab6e575a 100644 --- a/tests/template/templates/if.html +++ b/tests/template/templates/if.html @@ -2,6 +2,8 @@ 1 <!-- ELSEIF S_OTHER_VALUE --> 2 +<!-- ELSE IF S_OTHER_OTHER_VALUE --> +|S_OTHER_OTHER_VALUE| <!-- ELSE --> 03 <!-- ENDIF --> |