Skip to content

Commit 6564e4d

Browse files
committed
Allow filtering of child blocks by prefix; Add ancestor block to children
1 parent b58c1d2 commit 6564e4d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

ViewModel/Block/ChildRenderer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
class ChildRenderer extends AbstractRenderer
1010
{
1111
public function all(
12-
AbstractBlock $parentBlock
12+
AbstractBlock $parentBlock,
13+
string $blockAliasPrefix = '',
1314
): string {
1415
$html = '';
1516
$childNames = $parentBlock->getChildNames();
1617
$children = [];
1718

1819
foreach ($childNames as $childName) {
20+
if ($blockAliasPrefix && 0 !== strpos($childName, $blockAliasPrefix)) {
21+
continue;
22+
}
23+
1924
$childBlock = $parentBlock->getLayout()->getBlock($childName);
2025
if (false === $childBlock instanceof AbstractBlock) {
2126
if ($this->isDeveloperMode()) {
@@ -32,6 +37,7 @@ public function all(
3237
$sortedChildren = $this->sortBlocks($children);
3338

3439
foreach ($sortedChildren as $sortedChild) {
40+
$sortedChild->setAncestorBlock($parentBlock);
3541
$html .= $sortedChild->toHtml();
3642
}
3743

0 commit comments

Comments
 (0)