From: Fabien Potencier Date: Tue, 28 Dec 2010 18:30:49 +0000 (+0100) Subject: added the possibility to have tags in the global scope (outside blocks) in a child... X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=0177df4f7c95de55b69f926b9518d5aec38c9223;p=web%2Fkonrad%2Ftwig.git added the possibility to have tags in the global scope (outside blocks) in a child template --- diff --git a/lib/Twig/Node/BlockReference.php b/lib/Twig/Node/BlockReference.php index e195c7f..23097f5 100644 --- a/lib/Twig/Node/BlockReference.php +++ b/lib/Twig/Node/BlockReference.php @@ -16,7 +16,7 @@ * @package twig * @author Fabien Potencier */ -class Twig_Node_BlockReference extends Twig_Node +class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInterface { public function __construct($name, $lineno, $tag = null) { diff --git a/lib/Twig/Node/Include.php b/lib/Twig/Node/Include.php index cfc8599..3be3832 100644 --- a/lib/Twig/Node/Include.php +++ b/lib/Twig/Node/Include.php @@ -16,7 +16,7 @@ * @package twig * @author Fabien Potencier */ -class Twig_Node_Include extends Twig_Node +class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface { public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $variables = null, $only = false, $lineno, $tag = null) { diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index d8c3641..2355d7c 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -105,9 +105,9 @@ class Twig_Node_Module extends Twig_Node $compiler->write("\$context = array_merge(\$this->env->getGlobals(), \$context);\n\n"); if (null !== $this->getNode('parent')) { - // remove all but import nodes + // remove all output nodes foreach ($this->getNode('body') as $node) { - if ($node instanceof Twig_Node_Import) { + if (!$node instanceof Twig_NodeOutputInterface) { $compiler->subcompile($node); } } diff --git a/lib/Twig/Node/Print.php b/lib/Twig/Node/Print.php index 0927a8d..0746c4d 100644 --- a/lib/Twig/Node/Print.php +++ b/lib/Twig/Node/Print.php @@ -16,7 +16,7 @@ * @package twig * @author Fabien Potencier */ -class Twig_Node_Print extends Twig_Node +class Twig_Node_Print extends Twig_Node implements Twig_NodeOutputInterface { public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null) { diff --git a/lib/Twig/Node/Text.php b/lib/Twig/Node/Text.php index 7353380..f664e33 100644 --- a/lib/Twig/Node/Text.php +++ b/lib/Twig/Node/Text.php @@ -16,7 +16,7 @@ * @package twig * @author Fabien Potencier */ -class Twig_Node_Text extends Twig_Node +class Twig_Node_Text extends Twig_Node implements Twig_NodeOutputInterface { public function __construct($data, $lineno) { diff --git a/lib/Twig/NodeOutputInterface.php b/lib/Twig/NodeOutputInterface.php new file mode 100644 index 0000000..a75154c --- /dev/null +++ b/lib/Twig/NodeOutputInterface.php @@ -0,0 +1,20 @@ + + */ +interface Twig_NodeOutputInterface +{ +} diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 06830e2..7307386 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -244,13 +244,13 @@ class Twig_Parser implements Twig_ParserInterface protected function checkBodyNodes($body) { - // check that the body only contains block references and empty text nodes + // check that the body does not contain non-empty output nodes foreach ($body as $node) { if ( ($node instanceof Twig_Node_Text && !ctype_space($node->getAttribute('data'))) || - (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && !$node instanceof Twig_Node_Import) + (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface) ) { throw new Twig_Error_Syntax(sprintf('A template that extends another one cannot have a body (%s).', $node), $node->getLine()); }