Skip to content

Commit 4fa9a19

Browse files
authored
Merge pull request #15 from Paneon/feature/SHODEVS2-26
SHODEVS2-26 add attribute handling for data-twig-if
2 parents cb741b2 + 33b6e8f commit 4fa9a19

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/Compiler.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function convert(): string
7878

7979
$html = $this->replacePlaceholders($html);
8080

81-
if($this->stripWhitespace) {
81+
if ($this->stripWhitespace) {
8282
$html = $this->stripWhitespace($html);
8383
}
8484

@@ -248,7 +248,12 @@ private function handleIf(DOMElement $node): void
248248
}
249249

250250
if ($node->hasAttribute('v-if')) {
251-
$condition = $node->getAttribute('v-if');
251+
252+
if ($node->hasAttribute('data-twig-if')) {
253+
$condition = $node->getAttribute('data-twig-if');
254+
} else {
255+
$condition = $node->getAttribute('v-if');
256+
}
252257
$condition = $this->sanitizeCondition($condition);
253258

254259
// Open with if
@@ -262,8 +267,14 @@ private function handleIf(DOMElement $node): void
262267
$this->lastCloseIf = $closeIf;
263268

264269
$node->removeAttribute('v-if');
270+
$node->removeAttribute('data-twig-if');
265271
} elseif ($node->hasAttribute('v-else-if')) {
266-
$condition = $node->getAttribute('v-else-if');
272+
273+
if ($node->hasAttribute('data-twig-if')) {
274+
$condition = $node->getAttribute('data-twig-if');
275+
} else {
276+
$condition = $node->getAttribute('v-else-if');
277+
}
267278
$condition = $this->sanitizeCondition($condition);
268279

269280
// Replace old endif with else
@@ -275,6 +286,7 @@ private function handleIf(DOMElement $node): void
275286
$this->lastCloseIf = $closeIf;
276287

277288
$node->removeAttribute('v-else-if');
289+
$node->removeAttribute('data-twig-if');
278290
} elseif ($node->hasAttribute('v-else')) {
279291
// Replace old endif with else
280292
$this->lastCloseIf->textContent = $this->builder->createElse();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div>
2+
{% if array|length %}
3+
<div>
4+
<h1>Headline</h1>
5+
</div>
6+
{% elseif array|length < 100 %}
7+
<div>
8+
<h1>Headline</h1>
9+
</div>
10+
{% endif %}
11+
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<div>
3+
<div v-if="array.length" data-twig-if="array|length">
4+
<h1>Headline</h1>
5+
</div>
6+
<div v-else-if="array.length < 100" data-twig-if="array|length < 100">
7+
<h1>Headline</h1>
8+
</div>
9+
</div>
10+
</template>

0 commit comments

Comments
 (0)