Compatible with Joomla 5 and Joomla 6 (PHP 8.x). This tutorial shows how to display a single Custom Field or multiple Custom Fields inside a Joomla article template override, using their field names instead of numeric array positions.
Go to System → Site Templates → Your Template → Create Overrides and select Components → com_content → article. Joomla creates the following file:
templates/YOUR_TEMPLATE/html/com_content/article/default.php
You can also add the examples to an existing article layout override. Insert the PHP code in the override file on the server, not into the Joomla article itself.
Near the beginning of your article override, after defined('_JEXEC') or die; and any existing initialization code, add:
<?php
$fields = [];
if (!empty($this->item->jcfields) && is_array($this->item->jcfields)) {
foreach ($this->item->jcfields as $field) {
$fields[$field->name] = $field;
}
}
?>
This makes each field accessible by its unique Name (for example, tour-dates). It avoids relying on the order of the jcfields array.
Instead of:
<?php echo $this->item->jcfields[4]->value; ?>
Use:
<?php echo $fields['tour-dates']->value ?? ''; ?>
Assume that the article has a Text Custom Field whose Name is tour-dates. To show its value:
<?php echo $fields['tour-dates']->value ?? ''; ?>
For a plain-text field, it is better to check for an empty value and escape the text before printing it:
<?php if (!empty($fields['tour-dates']->value)) : ?>
<div class="tour-dates">
<?php echo htmlspecialchars(
(string) $fields['tour-dates']->value,
ENT_QUOTES,
'UTF-8'
); ?>
</div>
<?php endif; ?>
Once the $fields array is built, you can use it throughout the same override. Example with tour-dates, tour-location and tour-price:
<div class="tour-details">
<?php foreach (['tour-dates', 'tour-location', 'tour-price'] as $name) : ?>
<?php if (!empty($fields[$name]->value)) : ?>
<div class="mb-2">
<strong><?php echo htmlspecialchars(
(string) $fields[$name]->title,
ENT_QUOTES,
'UTF-8'
); ?>:</strong>
<?php echo htmlspecialchars(
(string) $fields[$name]->value,
ENT_QUOTES,
'UTF-8'
); ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
The example uses the Joomla field title as the visible caption and Bootstrap 5 spacing classes. Replace the names with your own field names.
<?php if (!empty($fields['tour-dates']->value)) : ?>
<div class="tour-dates">
<strong><?php echo htmlspecialchars(
(string) $fields['tour-dates']->title,
ENT_QUOTES,
'UTF-8'
); ?>:</strong>
<?php echo htmlspecialchars(
(string) $fields['tour-dates']->value,
ENT_QUOTES,
'UTF-8'
); ?>
</div>
<?php endif; ?>
| Property | Description |
|---|---|
name |
Unique machine-readable field name |
title |
Field title |
value |
Prepared field value; presentation depends on the field type |
rawvalue |
Original stored field value |
type |
Custom Field type |
For example:
<?php echo $fields['tour-dates']->rawvalue ?? ''; ?>
Note: These plain-text examples assume a scalar text value. Some field types (such as media, editor, list with multiple selections, or third-party fields) may produce HTML or arrays and need type-specific rendering. Do not blindly pass arrays into htmlspecialchars(). For Joomla-managed field presentation, consider the core field layout/renderer instead.
To loop through all fields in the prepared array:
<?php if (!empty($fields)) : ?>
<div class="article-custom-fields">
<?php foreach ($fields as $field) : ?>
<?php if (is_scalar($field->value) && (string) $field->value !== '') : ?>
<div class="custom-field mb-2">
<strong><?php echo htmlspecialchars(
(string) $field->title,
ENT_QUOTES,
'UTF-8'
); ?>:</strong>
<?php echo htmlspecialchars(
(string) $field->value,
ENT_QUOTES,
'UTF-8'
); ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
This loop is for plain-text output. For automatic Joomla field rendering (including field-specific HTML), use the standard Joomla Fields layout as appropriate.
$this->item for the article view; category blog layouts commonly expose an $item variable instead. Check that jcfields is present on that object.This code combines the initialization and a single field in one snippet, suitable for an existing article override:
<?php
$fields = [];
if (!empty($this->item->jcfields) && is_array($this->item->jcfields)) {
foreach ($this->item->jcfields as $field) {
$fields[$field->name] = $field;
}
}
?>
<?php if (!empty($fields['tour-dates']->value)) : ?>
<div class="tour-dates mb-3">
<strong>Tour Dates:</strong>
<?php echo htmlspecialchars(
(string) $fields['tour-dates']->value,
ENT_QUOTES,
'UTF-8'
); ?>
</div>
<?php endif; ?>
Creating a field-name-indexed array once in a Joomla article override is a reliable approach when you need precise placement and custom markup. It is easier to maintain than numeric indexes and works well for a single field or several fields. Always choose the appropriate output handling for each field type.
Important: The PHP snippets above are documentation examples. They are displayed in the article as text; actual executable PHP belongs in your template override files.
This tutorial explains how to customize Joomla 6's built-in Articles - Categories module (mod_articles_categories) using two template overrides:
Both layouts support active-category highlighting, automatic expansion of parent categories, and optional article links.
No additional extensions or Joomla core modifications are required.
1. Download the Override Files
Download the two override packages and extract their contents.
Vertical Accordion:
Horizontal Dropdown:
You can install either layout or both.
2. Upload the Files
Using FTP or your hosting File Manager, navigate to:
/templates/YOUR_TEMPLATE/html/mod_articles_categories/
Replace YOUR_TEMPLATE with your active Joomla template name.
Create the directory if it does not exist.
Upload the extracted PHP files into this folder.
Important: Do not modify the original Joomla module files.
3. Configure the Articles - Categories Module
In the Joomla administrator panel:
Select the Override Layout
Under the module's Advanced tab, find Alternative Layout.
Choose:
Save the module.
4. How the Overrides Work
Both layouts display the categories according to the module settings.
The Vertical Accordion is suitable for sidebars, while the Horizontal Dropdown is suitable for header navigation or full-width sections.
5. Optional: Display Articles Inside Categories
Both overrides can also display article links below each category.
Open the corresponding main PHP file:
Find:
$showArticles = false;
$articlesPerCategory = 5;
To enable article links, change the settings to:
$showArticles = true;
$articlesPerCategory = 5;
This displays up to five articles per category.
To display all articles, set:
$articlesPerCategory = 0;
Save the file and upload it again if you edited it locally.
Note: These options are configured directly in the override PHP file, not in the module's administrator settings.
6. Using Both Layouts
You can use both overrides on the same website.
For example:
Simply create two module instances and select the appropriate Alternative Layout for each.
7. Troubleshooting
Override not available: Verify the filenames and the template override directory.
Subcategories not appearing: Check the module's Show Subcategories and Maximum Level Depth settings.
Active category not highlighted: Make sure the current category belongs to the hierarchy displayed by the module.
Articles not displayed: Check that $showArticles is set to true and that the category contains published, accessible articles.
Dropdown display issues: Check for CSS conflicts with your Joomla template, particularly overflow: hidden on parent containers.
Conclusion
These two template overrides enhance the Joomla 6 Articles - Categories module (mod_articles_categories) with interactive multilevel navigation.
The Vertical Accordion and Horizontal Dropdown provide flexible navigation while preserving Joomla's existing category structure and settings.
Both layouts can be used independently or together, without modifying Joomla core files.
ACCORDION DEMO
HORIZONTAL DEMO
Compatibility: Joomla 6
Module: Articles - Categories (mod_articles_categories)
Type: Template Override
Layouts: Vertical Accordion / Horizontal Dropdown