Skip to content

Commit 85d36a3

Browse files
committed
refactor(container): Improve HTML attributes handling in container templates
- Replaced direct usage of container attributes with a dynamically built HTML attributes string for better flexibility. - Updated content retrieval to ensure consistent use of containerRef for UUID and acceptTypes.
1 parent c01f845 commit 85d36a3

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

instructions/guide.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ if (!isset($containerRef)) {
753753
global $pageAsset;
754754

755755
$identifier = $containerRef->identifier ?? null;
756-
$contentlets = $containerRef->contentlets ?? null
756+
$uuid = $containerRef->uuid ?? null;
757+
$contentlets = $containerRef->contentlets ?? null;
757758

758759
// Container attributes for UVE
759760
$containerAttrs = [
@@ -764,11 +765,16 @@ $containerAttrs = [
764765
'data-max-contentlets' => $containerRef->maxContentlets ?? 0
765766
];
766767

768+
// Build container HTML attributes string
769+
$containerHtmlAttrs = '';
770+
foreach ($containerAttrs as $attr => $value) {
771+
if ($value !== null && $value !== '') {
772+
$containerHtmlAttrs .= ' ' . $attr . '="' . htmlspecialchars($value) . '"';
773+
}
774+
}
767775
?>
768-
<div<?= $containerAttrs ?>>
776+
<div<?= $containerHtmlAttrs ?>>
769777
<?php
770-
$contentlets = $containerRef->contentlets
771-
772778
if ($contentlets) {
773779
foreach ($contentlets as $contentlet) {
774780
// Contentlet attributes for UVE
@@ -782,8 +788,8 @@ $containerAttrs = [
782788
'data-dot-container' => json_encode([
783789
'identifier' => $identifier,
784790
'uuid' => $uuid,
785-
'acceptTypes' => $container->acceptTypes ?? [],
786-
'maxContentlets' => $container->maxContentlets ?? 0,
791+
'acceptTypes' => $containerRef->acceptTypes ?? [],
792+
'maxContentlets' => $containerRef->maxContentlets ?? 0,
787793
'variantId' => $containerRef->variantId ?? null
788794
])
789795
];

0 commit comments

Comments
 (0)