The `{% put %}` tag now appends by default, The closing put tag now supports overwrite, eg: `{% endput overwrite %}`.

This commit is contained in:
Sam Georges 2014-09-06 17:10:52 +10:00
parent 14c8bc9a49
commit 37e5894df2
4 changed files with 20 additions and 7 deletions

View File

@ -1,6 +1,8 @@
* **Build 14x** (2014-09-xx)
- Various fixes to the RelationController relating to belongsToMany relations.
- Tree Lists are now collapsed by default to better handle large data sets.
- The `{% put %}` tag now appends by default.
- The closing put tag now supports **overwrite**, eg: `{% endput overwrite %}`.
* **Build 141** (2014-09-04)
- Add new `dump()` Twig function (config app.debug must be true).

View File

@ -209,8 +209,8 @@ class Extension extends Twig_Extension
/**
* Closes a layout block.
*/
public function endBlock()
public function endBlock($append = true)
{
Block::endBlock();
Block::endBlock($append);
}
}

View File

@ -12,9 +12,9 @@ use Twig_NodeInterface;
*/
class PutNode extends Twig_Node
{
public function __construct(Twig_NodeInterface $body, $name, $lineno, $tag = 'put')
public function __construct(Twig_NodeInterface $body, $name, $endType, $lineno, $tag = 'put')
{
parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag);
parent::__construct(['body' => $body], ['name' => $name, 'endType' => $endType], $lineno, $tag);
}
/**
@ -31,11 +31,15 @@ class PutNode extends Twig_Node
->write(");\n")
;
$isOverwrite = strtolower($this->getAttribute('endType')) == 'overwrite';
$compiler->subcompile($this->getNode('body'));
$compiler
->addDebugInfo($this)
->write("echo \$this->env->getExtension('CMS')->endBlock();\n")
;
->write("echo \$this->env->getExtension('CMS')->endBlock(")
->raw($isOverwrite ? 'false' : 'true')
->write(");\n")
;
}
}

View File

@ -33,13 +33,20 @@ class PutTokenParser extends Twig_TokenParser
*/
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
$stream->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'decidePutEnd'], true);
$endType = null;
if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
$endType = $token->getValue();
}
$stream->expect(Twig_Token::BLOCK_END_TYPE);
return new PutNode($body, $name, $token->getLine(), $this->getTag());
return new PutNode($body, $name, $endType, $lineno, $this->getTag());
}
public function decidePutEnd(Twig_Token $token)