aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/template/twig/node
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2013-06-10 11:17:11 -0500
committerNathan Guse <nathaniel.guse@gmail.com>2013-06-10 11:17:11 -0500
commit15114067e6c88e4ec8fa9d1ff66fd0de28b1144f (patch)
treea6aaf6afb52c67c984329f472b9f0e321a99ed24 /phpBB/includes/template/twig/node
parentb775f67128c1c851a2e3343b230d2861e5431528 (diff)
downloadforums-15114067e6c88e4ec8fa9d1ff66fd0de28b1144f.tar
forums-15114067e6c88e4ec8fa9d1ff66fd0de28b1144f.tar.gz
forums-15114067e6c88e4ec8fa9d1ff66fd0de28b1144f.tar.bz2
forums-15114067e6c88e4ec8fa9d1ff66fd0de28b1144f.tar.xz
forums-15114067e6c88e4ec8fa9d1ff66fd0de28b1144f.zip
[feature/twig] Replace phpBB template code with Twig syntax, then parse w/Twig
Fixing begin token/node, adding includejs token/node PHPBB3-11598
Diffstat (limited to 'phpBB/includes/template/twig/node')
-rw-r--r--phpBB/includes/template/twig/node/begin.php19
-rw-r--r--phpBB/includes/template/twig/node/includejs.php50
2 files changed, 60 insertions, 9 deletions
diff --git a/phpBB/includes/template/twig/node/begin.php b/phpBB/includes/template/twig/node/begin.php
index 1d47e35d87..52e0a96f2a 100644
--- a/phpBB/includes/template/twig/node/begin.php
+++ b/phpBB/includes/template/twig/node/begin.php
@@ -31,40 +31,41 @@ class phpbb_template_twig_node_begin extends Twig_Node
public function compile(Twig_Compiler $compiler)
{
$compiler
- ->write("if (!isset(\$blocks)) {\n")
+ ->write("if (!isset(\$loops)) {\n")
->indent()
- ->write("\$blocks = array();")
+ ->write("\$loops = array();")
->write("\$nestingLevel = 0;")
->outdent()
->write("}\n")
- ->write("\$blocks[\$nestingLevel] = array();\n")
+ ->write("\$loops[\$nestingLevel] = array();\n")
;
if (null !== $this->getNode('else')) {
- $compiler->write("\$blocks[\$nestingLevel]['iterated'] = false;\n");
+ $compiler->write("\$loops[\$nestingLevel]['iterated'] = false;\n");
}
$compiler
- ->write("foreach (\$context['_phpbb_blocks']['")
+ ->write("if (isset(\$context['loop'])) {")
+ ->write("foreach (\$context['loop']['")
->write($this->getAttribute('beginName'))
- ->write("'] as \$blocks[\$nestingLevel]['i'] => \$blocks[\$nestingLevel]['values']) {")
+ ->write("'] as \$loops[\$nestingLevel]['i'] => \$loops[\$nestingLevel]['values']) {")
->indent()
;
$compiler->subcompile($this->getNode('body'));
if (null !== $this->getNode('else')) {
- $compiler->write("\$blocks[\$nestingLevel]['iterated'] = true;\n");
+ $compiler->write("\$loops[\$nestingLevel]['iterated'] = true;\n");
}
$compiler
->outdent()
- ->write("}\n")
+ ->write("}}\n")
;
if (null !== $this->getNode('else')) {
$compiler
- ->write("if (!\$blocks[\$nestingLevel]['iterated']) {\n")
+ ->write("if (!\$loops[\$nestingLevel]['iterated']) {\n")
->indent()
->subcompile($this->getNode('else'))
->outdent()
diff --git a/phpBB/includes/template/twig/node/includejs.php b/phpBB/includes/template/twig/node/includejs.php
new file mode 100644
index 0000000000..e30ab75125
--- /dev/null
+++ b/phpBB/includes/template/twig/node/includejs.php
@@ -0,0 +1,50 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2009 Fabien Potencier
+ * (c) 2009 Armin Ronacher
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Represents an include node.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class phpbb_template_twig_node_includejs extends Twig_Node_Include
+{
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler->addDebugInfo($this);
+
+ $compiler
+ ->write("try {\n")
+ ->indent()
+ ;
+
+ $this->addGetTemplate($compiler);
+
+ $compiler->raw('->display(');
+
+ $this->addTemplateArguments($compiler);
+
+ $compiler->raw(");\n");
+
+ $compiler
+ ->write("} catch (Twig_Error_Loader \$e) {\n")
+ ->indent()
+ ->write("// ignore missing template\n")
+ ->outdent()
+ ->write("}\n\n")
+ ;
+ }
+}