Skip to content

Commit

Permalink
[TwigBundle] fixed include tag to reflect the new syntax from Twig
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Nov 19, 2010
1 parent 17c500e commit 84cf569
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/Symfony/Bundle/TwigBundle/Node/IncludeNode.php
Expand Up @@ -18,9 +18,9 @@
*/
class IncludeNode extends \Twig_Node
{
public function __construct(\Twig_Node_Expression $expr, \Twig_Node_Expression $variables = null, $lineno, $tag = null)
public function __construct(\Twig_Node_Expression $expr, \Twig_Node_Expression $variables = null, $only = false, $lineno, $tag = null)
{
parent::__construct(array('expr' => $expr, 'variables' => $variables), array(), $lineno, $tag);
parent::__construct(array('expr' => $expr, 'variables' => $variables), array('only' => (Boolean) $only), $lineno, $tag);
}

/**
Expand All @@ -37,10 +37,22 @@ public function compile($compiler)
->raw(', ')
;

if (null === $this->getNode('variables')) {
$compiler->raw('$context');
if (false === $this->getAttribute('only')) {
if (null === $this->getNode('variables')) {
$compiler->raw('$context');
} else {
$compiler
->raw('array_merge($context, ')
->subcompile($this->getNode('variables'))
->raw(')')
;
}
} else {
$compiler->subcompile($this->getNode('variables'));
if (null === $this->getNode('variables')) {
$compiler->raw('array()');
} else {
$compiler->subcompile($this->getNode('variables'));
}
}

$compiler->raw(");\n");
Expand Down
Expand Up @@ -37,9 +37,17 @@ public function parse(\Twig_Token $token)

$variables = $this->parser->getExpressionParser()->parseExpression();
}

$only = false;
if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'only')) {
$this->parser->getStream()->next();

$only = true;
}

$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);

return new IncludeNode($expr, $variables, $token->getLine(), $this->getTag());
return new IncludeNode($expr, $variables, $only, $token->getLine(), $this->getTag());
}

/**
Expand Down

0 comments on commit 84cf569

Please sign in to comment.