mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 10:56:38 +00:00
fixed filter tag
This commit is contained in:
@@ -245,7 +245,7 @@ class Twig_ExpressionParser
|
||||
}
|
||||
|
||||
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'))) {
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,6 +30,10 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
|
||||
*/
|
||||
public function compile(Twig_Compiler $compiler)
|
||||
{
|
||||
if ($this->getAttribute('as_string')) {
|
||||
$compiler->raw('(string) ');
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw("\$this->renderBlock(")
|
||||
->subcompile($this->getNode('name'))
|
||||
|
||||
@@ -20,7 +20,7 @@ class Twig_TokenParser_Filter extends Twig_TokenParser
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
--TEST--
|
||||
"filter" tag applies a filter on its children
|
||||
--TEMPLATE--
|
||||
{% filter json_encode|raw %}test{% endfilter %}
|
||||
--DATA--
|
||||
return array()
|
||||
--EXPECT--
|
||||
"test"
|
||||
Reference in New Issue
Block a user