Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/View/Antlers/Language/Runtime/NodeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ protected function checkPartialForNamedSlots(AntlersNode $node)
$namedSlots = [];

foreach ($node->children as $child) {
if ($child instanceof AntlersNode && ! $child->isComment && $child->name->name == 'slot') {
if ($child instanceof AntlersNode && ! $child->isComment && $child->isPaired() && $child->name->name == 'slot') {
$namedSlots[$child->name->methodPart] = $child;
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Antlers/Runtime/PartialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,27 @@ public function test_assignments_in_earlier_partials_do_not_blank_a_later_partia

$this->assertSame('FILTERhi<slot>KEEPME</slot>', $this->renderString($template, [], true));
}

public function test_named_slots_render_inside_a_nested_partial_that_uses_the_default_slot()
{
$template = <<<'EOT'
{{ partial:accordion index="1" }}
{{ slot:title }}<h2>The Title</h2>{{ /slot:title }}
{{ slot:icon }}<button>+</button>{{ /slot:icon }}
{{ slot:body }}<p>The Body</p>{{ /slot:body }}
{{ /partial:accordion }}
EOT;

$accordion = <<<'EOT'
<div id="accordion-{{ index }}">{{ partial:flex_column class="p-6" }}<div class="header">{{ slot:title }}{{ slot:icon }}</div><div class="content">{{ slot:body }}</div>{{ /partial:flex_column }}</div>
EOT;

$this->withFakeViews();
$this->viewShouldReturnRaw('accordion', $accordion);
$this->viewShouldReturnRaw('flex_column', '<div class="flex flex-col {{ class }}">{{ slot }}</div>');

$expected = '<div id="accordion-1"><div class="flex flex-col p-6"><div class="header"><h2>The Title</h2><button>+</button></div><div class="content"><p>The Body</p></div></div></div>';

$this->assertSame($expected, $this->renderString($template, [], true));
}
}
Loading