Skip to content

Commit

Permalink
feature #2045 Adds Twig_NodeCaptureInterface for nodes that capture a…
Browse files Browse the repository at this point in the history
…ll output
  • Loading branch information
brandonkelly authored and fabpot committed Jan 10, 2017
1 parent 3cdbd32 commit bc6a913
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Twig/Node/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Twig_Node_Set extends Twig_Node
class Twig_Node_Set extends Twig_Node implements Twig_NodeCaptureInterface
{
public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null)
{
Expand Down
19 changes: 19 additions & 0 deletions lib/Twig/NodeCaptureInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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 node that will capture any nested displayable nodes.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface Twig_NodeCaptureInterface
{
}
4 changes: 2 additions & 2 deletions lib/Twig/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ protected function filterBodyNodes(Twig_NodeInterface $node)
throw new Twig_Error_Syntax('A template that extends another one cannot include contents outside Twig blocks. Did you forget to put the contents inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext());
}

// bypass "set" nodes as they "capture" the output
if ($node instanceof Twig_Node_Set) {
// bypass nodes that will "capture" the output
if ($node instanceof Twig_NodeCaptureInterface) {
return $node;
}

Expand Down

0 comments on commit bc6a913

Please sign in to comment.