1

I have created some custom fields in my Joomla article from backend

templates/name-template/html/com_content/article/default.php

and use this code for load custom fields at joomla article

<?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 echo ($fields['name-field']->value); ?>

now I want to fetch custom fields in Layouts in Joomla

templates/name-template/html/layouts/name-folder

but code above not work for load custom fields

and load layouts with this code at Joomla article default.php

<?php echo JLayoutHelper::render('name-folder.name-file', array('item' => $this->item)); ?>

Everything is right, but the custom fields not showing

How to show custom fields at layouts?

  • Assuming you copy-paste this code to layout as-is, $this->item is undefined. Instead use $displayData['item'] to access the article in the layout. – Sharky Feb 2 at 13:31
  • @Sharky thank you so much..thats work 👌 – niaziblog Feb 2 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.