Skip to content

Commit 2d98e1c

Browse files
committed
Add DOM ID to all blocks being converted to Alpine component
1 parent 95e8917 commit 2d98e1c

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Observer/AddAlpineComponents.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ private function addComponentNameToHtml(
5151
): string {
5252
$additional = 'x-data="'.$componentName.'"';
5353

54+
$blockId = str_replace('.', '-', $block->getNameInLayout());
55+
if (false === str_contains($html, ' id="' . $blockId . '"')) {
56+
$additional .= ' id="' . $blockId . '"';
57+
}
58+
5459
if ($this->isDeveloperMode()) {
55-
$blockName = str_replace('.', '-', $block->getNameInLayout());
56-
$additional .= ' x-title="'.$blockName.'"';
60+
$additional .= ' x-title="' . $blockId . '"';
5761
}
5862

5963
return preg_replace('/^<([a-z]+)/', '<\1 '.$additional, $html);

0 commit comments

Comments
 (0)