Skip to content

Commit

Permalink
BlockMacros: "extends check" skipped for nested blocks [Closes #227]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 15, 2020
1 parent 22c93d3 commit 1422496
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Latte/Macros/BlockMacros.php
Expand Up @@ -298,7 +298,7 @@ public function macroBlock(MacroNode $node, PhpWriter $writer)
if (isset($this->namedBlocks[$name])) {
throw new CompileException("Cannot redeclare static {$node->name} '$name'");
}
$extendsCheck = $this->namedBlocks
$extendsCheck = $this->namedBlocks || $node->parentNode
? ''
: 'if ($this->getParentName()) { return get_defined_vars();} ';
$this->namedBlocks[$name] = true;
Expand Down
28 changes: 28 additions & 0 deletions tests/Latte/BlockMacros.extendsCheck.phpt
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);

$template = '
{extends layout.latte}
{capture $foo}
{block bar}{/block}
{/capture}
{block content}
content
';

Assert::matchFile(
__DIR__ . '/expected/BlockMacros.extendsCheck.phtml',
$latte->compile($template)
);
24 changes: 24 additions & 0 deletions tests/Latte/expected/BlockMacros.extendsCheck.phtml
@@ -0,0 +1,24 @@
<?php
%A%

final class Template%a% extends Latte\Runtime\Template
{
%A%
public function main(): array
{
extract($this->params);
?>


<?php ob_start(function () {}) ?> <?php
$this->renderBlock('bar', get_defined_vars());
$__fi = new LR\FilterInfo('html');
$foo = ob_get_length() ? new LR\Html(ob_get_clean()) : ob_get_clean();
?>

<?php
$this->renderBlock('content', get_defined_vars());
return get_defined_vars();
}
%A%
}

0 comments on commit 1422496

Please sign in to comment.