From 612dbad63fa6f85fdaa0298e67f89d7c9010dbe6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 11 Jun 2013 10:57:00 -0500 Subject: [PATCH] [feature/twig] Fixing IF .blah correctly PHPBB3-11598 --- phpBB/includes/template/twig/lexer.php | 29 +++++++++++++++++++------- phpBB/includes/template/twig/twig.php | 7 ++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/template/twig/lexer.php b/phpBB/includes/template/twig/lexer.php index 4402760a7b..71e3e9c27e 100644 --- a/phpBB/includes/template/twig/lexer.php +++ b/phpBB/includes/template/twig/lexer.php @@ -38,20 +38,35 @@ class phpbb_template_twig_lexer extends Twig_Lexer 'ENDPHP', 'EVENT', ); - + // Replace with {% include 'blah.html' %} $code = preg_replace('##', "{% INCLUDE$1 '$2' %}", $code); + // This strips the $ inside of a tag directly after the token, which was used in #', '', $code); + + // This strips the . inside of a tag directly before a variable name, which was used in #', array($this, 'tag_if_cleanup'), $code); + // Replace all of our starting tokens, with Twig style, {% TOKEN %} - // This also strips the $ inside of a tag directly after the token, which was used in becomes - $code = preg_replace('##', '{% $1 $2$4 %}', $code); - + $code = preg_replace('##', '{% $1 $2 %}', $code); + // Replace all of our variables, {VARNAME} or {$VARNAME}, with Twig style, {{ VARNAME }} $code = preg_replace('#{\$?([a-zA-Z0-9_\.]+)}#', '{{ $1 }}', $code); -//echo $code; -//exit; + return parent::tokenize($code, $filename); } + + /** + * preg_replace_callback to clean up IF statements + * + * This strips the . inside of a tag directly before a variable name, which was used in '; + } } diff --git a/phpBB/includes/template/twig/twig.php b/phpBB/includes/template/twig/twig.php index 81c03b6ef1..a067827f70 100644 --- a/phpBB/includes/template/twig/twig.php +++ b/phpBB/includes/template/twig/twig.php @@ -347,6 +347,11 @@ class phpbb_template_twig implements phpbb_template return $this->context->alter_block_array($blockname, $vararray, $key, $mode); } + /** + * Get template vars in a format Twig will use (from the context) + * + * @return array + */ protected function get_template_vars() { $vars = array(); @@ -354,7 +359,7 @@ class phpbb_template_twig implements phpbb_template // Work-around for now foreach ($this->user->lang as $key => $value) { - if (is_array($value)) + if (!is_string($value)) { continue; }