I have created one subform custom fields in my Joomla 4 article from backend and selected media filed at subform enter image description here enter image description here and use this code for load custom fields at joomla article


code :

$context = 'com_content.article';
$article = $this->item;

//use the field helper class to get the fields
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$fields = FieldsHelper::getFields($context, $article, true);
// Added so as to access fields by their name

foreach($fields as $field) {
    $fields[$field->name] = $field;

and use this code for fetch

$programs = $fields['gallery']->rawvalue;
$class = $fields['gallery']->params->get('render_class');
$items = json_decode($programs, true);?>

<?php $i = 0; foreach($items as $program): ?>
<div class="program <?php echo $class; ?>">
    <div class="program__image">
        <?php echo $program['media']; ?>

<?php $i++; endforeach; ?>

now I want to render just subform custom fields value in joomla article


but code above not work for load subform custom fields joomla4 but loaded repeatable custom fields joomla3

How to render subform custom fields at joomla4 article ?

  • To use a column as new first-level keys, instead of foreach($fields as $field) { $fields[$field->name] = $field; }, you can use $fields = array_column($fields, null, 'name'); Maintaining $i in your snippet doesn't seem useful.
    – mickmackusa
    May 26 at 0:24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.