I have created one subform custom fields in my Joomla 4 article from backend and selected media filed at subform
and use this code for load custom fields at joomla article
YOUR_JOOMLA_WEBSITE_ROOT/templates/cassiopeia/html/com_content/article/default.php
code :
<?php
$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
// GET CUSTOM FIELDS
foreach($fields as $field) {
$fields[$field->name] = $field;
}
?>
and use this code for fetch
<?php
$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']; ?>
</div>
</div>
<?php $i++; endforeach; ?>
now I want to render just subform custom fields value in joomla article
YOUR_JOOMLA_WEBSITE_ROOT/templates/cassiopeia/html/com_content/article/default.php
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 ?
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.