diff --git a/src/models/ImgTag.php b/src/models/ImgTag.php index d20ed7c..d5ecdc1 100644 --- a/src/models/ImgTag.php +++ b/src/models/ImgTag.php @@ -106,8 +106,13 @@ public function render(): Markup if ($this->loadingStrategy !== 'eager') { $attrs = $this->swapLazyLoadAttrs($this->loadingStrategy, $this->placeholder, $attrs); } - // Remove any empty attributes - $attrs = array_filter($attrs); + + // Remove any empty attributes except the alt attribute + $attrs = array_filter($attrs, function($value, $key) { + // Keep the 'alt' attribute even if it's empty + return $key === 'alt' || !empty($value); + }, ARRAY_FILTER_USE_BOTH); + // Render the tag $tag = Html::tag('img', '', $attrs); diff --git a/src/models/PictureTag.php b/src/models/PictureTag.php index d38d2a1..846be1a 100644 --- a/src/models/PictureTag.php +++ b/src/models/PictureTag.php @@ -174,8 +174,13 @@ public function render(): Markup if ($this->loadingStrategy !== 'eager') { $attrs = $this->swapLazyLoadAttrs($this->loadingStrategy, $this->placeholder, $attrs); } - // Remove any empty attributes - $attrs = array_filter($attrs); + + // Remove any empty attributes except the alt attribute + $attrs = array_filter($attrs, function($value, $key) { + // Keep the 'alt' attribute even if it's empty + return $key === 'alt' || !empty($value); + }, ARRAY_FILTER_USE_BOTH); + // Render the tag $content .= Html::tag('img', '', $attrs); // Handle the tag