[feature/twig] BEGIN loops now work

PHPBB3-11598
This commit is contained in:
Nathan Guse 2013-06-10 11:57:51 -05:00
parent 15114067e6
commit eac3c1f75c
2 changed files with 4 additions and 5 deletions

View file

@ -49,7 +49,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer
$code = preg_replace('#<!-- (' . implode('|', $valid_starting_tokens) . ') (not )?(\$|\.)?(?:(.*?) ?)?-->#', '{% $1 $2$4 %}', $code);
// Replace all of our variables, {VARNAME} or {$VARNAME}, with Twig style, {{ VARNAME }}
$code = preg_replace('#{\$?([A-Z_][A-Z_0-9]+)}#', '{{ $1 }}', $code);
$code = preg_replace('#{\$?([a-zA-Z0-9_\.]+)}#', '{{ $1 }}', $code);
//echo $code;
//exit;
return parent::tokenize($code, $filename);

View file

@ -45,10 +45,9 @@ class phpbb_template_twig_node_begin extends Twig_Node
}
$compiler
->write("if (isset(\$context['loop'])) {")
->write("foreach (\$context['loop']['")
->write($this->getAttribute('beginName'))
->write("'] as \$loops[\$nestingLevel]['i'] => \$loops[\$nestingLevel]['values']) {")
->write("if (isset(\$context['loop']['" . $this->getAttribute('beginName') . "'])) {")
->write("foreach (\$context['loop']['". $this->getAttribute('beginName'). "'] as \$" . $this->getAttribute('beginName') . ") {")
->write("\$context['". $this->getAttribute('beginName'). "'] = \$" . $this->getAttribute('beginName') . ";")
->indent()
;