PHP Joomla! 6 Joomla! 5 Joomla! 3 (Legacy) Template Override Intermediate

Render a Single Custom Field by Name in Overrides

Indexes $this->item->jcfields by field name and outputs a specific Custom Field anywhere inside a template override.

Updated on 24 November 2026 97 copies 368 views
templates/seu_template/html/com_content/article/default.php
<?php

declare(strict_types=1);

// Indexa todos os campos personalizados pelo nome (machine name)
$fieldsByName = [];
foreach (($this->item->jcfields ?? []) as $field) {
    $fieldsByName[$field->name] = $field;
}

$target = $fieldsByName['descricao-adicional'] ?? null;
?>
<?php if ($target && trim((string) $target->value) !== '') : ?>
    <div class="<?php echo htmlspecialchars((string) $target->params->get('render_class', ''), ENT_QUOTES, 'UTF-8'); ?>">
        <?php echo $target->value; ?>
    </div>
<?php endif; ?>
Maps jcfields by field name for clean O(1) lookup in Joomla 5 and 6 overrides.
templates/seu_template/html/com_content/article/default.php
<?php JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); ?>
<?php foreach ($this->item->jcfields as $kf => $field) : ?>
    <?php if ($field->name == 'descricao-adicional') : ?>
        <div class="<?php echo $field->params->get('render_class'); ?>">
            <?php echo $field->value; ?>
        </div>
    <?php endif; ?>
<?php endforeach; ?>
Original Joomla 3.7+ snippet using JLoader::register for FieldsHelper.

Technical explanation and best practices

For full layout control in article or portfolio overrides, set the Custom Field automatic display to "Do not automatically display" and place each field manually where your grid demands.

In Joomla 5 and 6, JLoader::register() is no longer needed: $this->item->jcfields is already populated on the item (or loaded via FieldsHelper::getFields() externally).

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.