* @package twig
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
-class Twig_Node_BlockReference extends Twig_Node
+class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInterface
{
public function __construct($name, $lineno, $tag = null)
{
* @package twig
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
-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)
{
$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);
}
}
* @package twig
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
-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)
{
* @package twig
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
-class Twig_Node_Text extends Twig_Node
+class Twig_Node_Text extends Twig_Node implements Twig_NodeOutputInterface
{
public function __construct($data, $lineno)
{
--- /dev/null
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2010 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Represents a displayable node in the AST.
+ *
+ * @package twig
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ */
+interface Twig_NodeOutputInterface
+{
+}
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());
}