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


and use this code for load custom fields at joomla article

$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

<?php echo ($fields['name-field']->value); ?>

now I want to fetch custom fields in Layouts in Joomla


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 '19 at 13:31

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.