* ``constant``
* ``cycle``
* ``parent``
+ * ``block``
* Tests:
wouldn't know which one of the blocks' content to use.
If you want to print a block multiple times you can however use the
-``display`` tag:
+``block`` function:
.. code-block:: jinja
<title>{% block title %}{% endblock %}</title>
- <h1>{% display title %}</h1>
+ <h1>{{ block('title') }}</h1>
{% block body %}{% endblock %}
Like PHP, Twig does not support multiple inheritance. So you can only have one
return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $node->getLine());
}
+ if ('block' === $node->getAttribute('name')) {
+ return new Twig_Node_Expression_BlockReference($args->getNode(0), $node->getLine());
+ }
+
if (null !== $alias = $this->parser->getImportedFunction($node->getAttribute('name'))) {
return new Twig_Node_Expression_GetAttr($alias['node'], new Twig_Node_Expression_Constant($alias['name'], $node->getLine()), $args, $node->getLine(), Twig_Node_Expression_GetAttr::TYPE_METHOD);
}
new Twig_TokenParser_Extends(),
new Twig_TokenParser_Include(),
new Twig_TokenParser_Block(),
- new Twig_TokenParser_Display(),
new Twig_TokenParser_Filter(),
new Twig_TokenParser_Macro(),
new Twig_TokenParser_Import(),
--- /dev/null
+<?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 a block call node.
+ *
+ * @package twig
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ */
+class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
+{
+ public function __construct(Twig_NodeInterface $name, $lineno, $tag = null)
+ {
+ parent::__construct(array('name' => $name), array(), $lineno, $tag);
+ }
+
+ /**
+ * Compiles the node to PHP.
+ *
+ * @param Twig_Compiler A Twig_Compiler instance
+ */
+ public function compile($compiler)
+ {
+ $compiler
+ ->raw("\$this->renderBlock(")
+ ->subcompile($this->getNode('name'))
+ ->raw(", \$context, \$blocks)")
+ ;
+ }
+}
+++ /dev/null
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) 2009 Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-class Twig_TokenParser_Display extends Twig_TokenParser
-{
- /**
- * Parses a token and returns a node.
- *
- * @param Twig_Token $token A Twig_Token instance
- *
- * @return Twig_NodeInterface A Twig_NodeInterface instance
- */
- public function parse(Twig_Token $token)
- {
- $lineno = $token->getLine();
- $name = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
-
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
-
- return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
- }
-
- /**
- * Gets the tag name associated with this token parser.
- *
- * @param string The tag name
- */
- public function getTag()
- {
- return 'display';
- }
-}