Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 25, 2024
1 parent 0d3a283 commit a93723e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/YieldingTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,22 @@ public function yieldParentBlock($name, array $context, array $blocks = [])
}
}

public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true, Template $templateContext = null)
public function renderParentBlock($name, array $context, array $blocks = [])
{
throw new RuntimeError(sprintf('Calling "%s" for block "%s" is not supported as "use_yield" is set to "true".', __METHOD__, $name), -1, $this->getSourceContext());
$content = '';
foreach ($this->yieldParentBlock($name, $context, $blocks) as $data) {
$content .= $data;
}

return $content;
}

public function displayParentBlock($name, array $context, array $blocks = [])
public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true, Template $templateContext = null)
{
throw new RuntimeError(sprintf('Calling "%s" for block "%s" is not supported as "use_yield" is set to "true".', __METHOD__, $name), -1, $this->getSourceContext());
}

public function renderParentBlock($name, array $context, array $blocks = [])
public function displayParentBlock($name, array $context, array $blocks = [])
{
throw new RuntimeError(sprintf('Calling "%s" for block "%s" is not supported as "use_yield" is set to "true".', __METHOD__, $name), -1, $this->getSourceContext());
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Fixtures/functions/parent_in_condition.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
"block" calling parent() in a conditional expression
--TEMPLATE--
{% extends "parent.twig" %}
{% block label %}{{ parent() ?: 'foo' }}{% endblock %}
--TEMPLATE(parent.twig)--
{% block label %}PARENT_LABEL{% endblock %}
--DATA--
return []
--EXPECT--
PARENT_LABEL

0 comments on commit a93723e

Please sign in to comment.