Skip to content

Commit 20d8564

Browse files
authored
Merge pull request #83 from tronsha/bugfix/props-slotfallback-order
Fix raw block order
2 parents 2592e34 + be197b4 commit 20d8564

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

src/Compiler.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,16 @@ public function convert(): string
227227
$resultNode = $this->convertNode($templateElement);
228228
$html = $this->document->saveHTML($resultNode);
229229

230-
if (count($this->rawBlocks)) {
231-
$html = implode("\n", $this->rawBlocks) . "\n" . $html;
232-
}
233-
234230
if (!$html) {
235231
throw new Exception('Generating html during conversion process failed.');
236232
}
237233

238-
$html = $this->addVariableBlocks($html);
234+
$this->rawBlocks[] = $this->createVariableBlock();
235+
236+
if (count($this->rawBlocks)) {
237+
$html = implode("\n", $this->rawBlocks) . "\n" . $html;
238+
}
239+
239240
$html = $this->replacePlaceholders($html);
240241
$html = $this->replaceScopedPlaceholders($html);
241242
$html = $this->replaceAttributeWithIfConditionPlaceholders($html);
@@ -1291,15 +1292,15 @@ protected function addVariable(string $name, $value): void
12911292
$this->variables[$name] = $value;
12921293
}
12931294

1294-
protected function addVariableBlocks(string $string): string
1295+
protected function createVariableBlock(): string
12951296
{
12961297
$blocks = [];
12971298

12981299
foreach ($this->variables as $varName => $varValue) {
12991300
$blocks[] = $this->builder->createMultilineVariable($varName, $varValue);
13001301
}
13011302

1302-
return implode('', $blocks) . $string;
1303+
return implode('', $blocks);
13031304
}
13041305

13051306
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% set text = text|default('foo') %}
2+
{% set slot_default_fallback %}{{ text }}{% endset %}
3+
{% set slot_default_value %}{{ slot_default|default(slot_default_fallback) }}{% endset %}
4+
{% include "/templates/ChildComponent.twig" with { 'slot_default': slot_default_value, 'class': "", 'style': "" } %}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<ChildComponent>
3+
<slot>{{ text }}</slot>
4+
</ChildComponent>
5+
</template>
6+
<script>
7+
export default {
8+
name: 'ComponentWithSlot',
9+
component: {
10+
ChildComponent,
11+
},
12+
props: {
13+
text: {
14+
type: String,
15+
default: 'foo'
16+
},
17+
},
18+
};
19+
</script>

0 commit comments

Comments
 (0)