PHP Joomla! 6 Joomla! 5 Joomla! 4 Template Override Básico

Limpar metadados #joomlaImage:// de image_intro e obter largura e altura

Decodifica o JSON de imagens do artigo e extrai URL limpa, width e height nativos com HTMLHelper::cleanImageURL() para evitar CLS.

Atualizado em 24 Novembro 2026 148 cópias 518 acessos
templates/seu_template/html/com_content/article/default.php
<?php

declare(strict_types=1);

use Joomla\CMS\HTML\HTMLHelper;

$images = json_decode((string) ($this->item->images ?? '{}'));
if (!empty($images->image_intro)) {
    $img    = HTMLHelper::cleanImageURL($images->image_intro);
    $src    = $img->url;
    $width  = (int) ($img->attributes['width'] ?? 0);
    $height = (int) ($img->attributes['height'] ?? 0);
    $alt    = (string) ($images->image_intro_alt ?: $this->item->title);
}
Retorna $img->url e $img->attributes['width']/['height'] prontos para HTML semântico.

Explicação técnica e boas práticas

Desde o Joomla 4, o Gerenciador de Mídia grava dimensões no formato images/foto.jpg#joomlaImage://local-images/foto.jpg?width=1200&height=630. Usar HTMLHelper::cleanImageURL() retorna a URL limpa e os atributos reais para renderizar <img width height loading="lazy"> sem Layout Shift (CLS).

Atendimento Direto

Tem um projeto Joomla ou desafio técnico em mente?

Do diagnóstico arquitetural ao deploy em produção, sem intermediários.