}
if ('block' === $node->getAttribute('name')) {
- return new Twig_Node_Expression_BlockReference($args->getNode(0), $node->getLine());
+ return new Twig_Node_Expression_BlockReference($args->getNode(0), false, $node->getLine());
}
if (null !== $alias = $this->parser->getImportedFunction($node->getAttribute('name'))) {
*/
class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
{
- public function __construct(Twig_NodeInterface $name, $lineno, $tag = null)
+ public function __construct(Twig_NodeInterface $name, $asString = false, $lineno, $tag = null)
{
- parent::__construct(array('name' => $name), array(), $lineno, $tag);
+ parent::__construct(array('name' => $name), array('as_string' => $asString), $lineno, $tag);
}
/**
*/
public function compile(Twig_Compiler $compiler)
{
+ if ($this->getAttribute('as_string')) {
+ $compiler->raw('(string) ');
+ }
+
$compiler
->raw("\$this->renderBlock(")
->subcompile($this->getNode('name'))
public function parse(Twig_Token $token)
{
$name = $this->parser->getVarName();
- $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), $token->getLine(), $this->getTag());
+ $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), true, $token->getLine(), $this->getTag());
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
--- /dev/null
+--TEST--
+"filter" tag applies a filter on its children
+--TEMPLATE--
+{% filter json_encode|raw %}test{% endfilter %}
+--DATA--
+return array()
+--EXPECT--
+"test"