diff options
| author | Nathan Guse <nathaniel.guse@gmail.com> | 2013-06-24 12:39:28 -0500 |
|---|---|---|
| committer | Nathan Guse <nathaniel.guse@gmail.com> | 2013-06-24 12:39:28 -0500 |
| commit | c958155fb63667e1d54d6d31489bf17c0a180dab (patch) | |
| tree | 05c535c0c7c35f8410f4b3414295ed97cec79aa1 /phpBB/includes/template/twig/node | |
| parent | 4881085f13f0b10636bf11f846f86562c1e6bfc9 (diff) | |
| download | forums-c958155fb63667e1d54d6d31489bf17c0a180dab.tar forums-c958155fb63667e1d54d6d31489bf17c0a180dab.tar.gz forums-c958155fb63667e1d54d6d31489bf17c0a180dab.tar.bz2 forums-c958155fb63667e1d54d6d31489bf17c0a180dab.tar.xz forums-c958155fb63667e1d54d6d31489bf17c0a180dab.zip | |
[feature/twig] Able to set chain of namespaces to search for loadTemplate()
This is done so that when event template files are included, if they
include files themselves, that namespace is checked first, then __main__
is checked to include the correct template file.
Also, when template files are included from a particular namespace, this is
done so that the files from that namespace are included first, then the
main namespace is checked.
We may want to change this behavior in the future to allow choosing which
locations have priority, but for now, this is what I am doing to make sure
the behavior is simple and always the same.
PHPBB3-11598
Diffstat (limited to 'phpBB/includes/template/twig/node')
| -rw-r--r-- | phpBB/includes/template/twig/node/event.php | 9 | ||||
| -rw-r--r-- | phpBB/includes/template/twig/node/include.php | 45 |
2 files changed, 53 insertions, 1 deletions
diff --git a/phpBB/includes/template/twig/node/event.php b/phpBB/includes/template/twig/node/event.php index c76c727ba5..cedfa870fa 100644 --- a/phpBB/includes/template/twig/node/event.php +++ b/phpBB/includes/template/twig/node/event.php @@ -37,7 +37,14 @@ class phpbb_template_twig_node_event extends Twig_Node if ($this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html')) { - $compiler->write("\$this->env->loadTemplate('@" . $ext_namespace . "/" . $location . ".html')->display(\$context);\n"); + $compiler + ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") + + // We set the namespace lookup order to be this extension first, then the main path + ->write("\$this->env->setNamespaceLookUpOrder(array('" . $ext_namespace . "', '__main__'));\n") + ->write("\$this->env->loadTemplate('@" . $ext_namespace . "/" . $location . ".html')->display(\$context);\n") + ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") + ; } } } diff --git a/phpBB/includes/template/twig/node/include.php b/phpBB/includes/template/twig/node/include.php new file mode 100644 index 0000000000..df7a95af44 --- /dev/null +++ b/phpBB/includes/template/twig/node/include.php @@ -0,0 +1,45 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_template_twig_node_include 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); + + $location = $this->getNode('expr')->getAttribute('value'); + $namespace = false; + + if (strpos($location, '@') === 0) + { + $namespace = substr($location, 1, strpos($location, '/') - 1); + + $compiler + ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") + + // We set the namespace lookup order to be this namespace first, then the main path + ->write("\$this->env->setNamespaceLookUpOrder(array('" . $namespace . "', '__main__'));\n") + ; + } + + parent::compile($compiler); + + if ($namespace) + { + $compiler + ->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n") + ; + } + } +} |
