TIPS - Custom fields for non-developer
- Details
- Written by: Mr Alexandre J-S William ELISÉ
- Category: Custom field
-
Also available:
- Hits: 2570

About 2mn to read
One at the top of the file and the other where you
...Read more:
One at the top of the file and the other where you want to show the custom field (This requires Joomla! 3.7.x minimum).
for example: In the file templates/example/html/com_content/article/defaut.php
<?php
defined('_JEXEC') or die();
//your template code...
// BEGIN: Code to add at the top of the file
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$fields_by_name = \Joomla\Utilities\ArrayHelper::pivot($this->item->jcfields, 'name');
// END: Code to add at the top
?>
<?php
//...
//Your template code...
//...
// BEGIN: Code to add where you want to show the custom field by name
echo $fields_by_name['my-custom-field']->label
. ':' . $fields_by_name['my-custom-field']->value;
// END: Code to add where you want to show the custom field by name
?>