Joomla category created - "Sample Category"
Custom fields group created for category - "Sample Group"
Custom fields type text created and assigned to "Sample Group" and to all categories - "Sample Custom Text Field"
Populated the Default value for the "Sample Custom Text Field" - "The default value of the sample custom text field"
Set the "Sample custom field" to be displayed AfterDisplay (It does not matter where. Is displayed just to check is correct. Using overrides it suppose to be hidden.
Edit the Sample Category by adding "The sample category custom text field" in the "Sample Custom Text Field"
Created overrides
/httpdocs/templates/protostar/html/com_content/category/blog.php
/httpdocs/templates/protostar/html/com_content/category/default.php
add
<?php
$category = JRequest::getInt('id');
echo 'cat id is: '. $category;
$currentCatFields = FieldsHelper::getFields('com_content.categories', $category, true);
echo '<pre>',print_r($currentCatFields,1),'</pre>';
?>
add
<?php
foreach ($this->item->jcfields as $field) :
php echo $field->label . ':' . $field->value;
endforeach
?>
The $currentCatFields->value is suppose to be "The sample category custom text field".
The jcfields suppose to be rendered.
see the result at:
http://unicserv.joomla.com/joomla/category-blog.html
http://unicserv.joomla.com/joomla/category-list.html
$currentCatFields->value is not existing at all. Strangely, some of the array is filled up, excepting the current values.
The rendering attempt have no results at all. See warning.
Warning: Invalid argument supplied for foreach() in /mnt/data/vhosts/casite-986486.cloudaccess.net/httpdocs/templates/protostar/html/com_content/category/blog.php on line 75
Joomla 3.9.1
PHP 7.0.32 (but it does not work on another versions as well.
How is suppose to access category's custom fields? The above trials where just a few from 2 days attempts of getting this work. There is no reference on internet excepting on how to get Article's custom fields on category list display. I need to access category's custom fields.
Labels |
Added:
?
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-12-19 17:25:41 |
Closed_By | ⇒ | joomla-cms-bot |
Closed_Date | 2018-12-19 17:25:41 | ⇒ | 2018-12-19 17:25:43 |
Closed_By | joomla-cms-bot | ⇒ | Quy |
Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/23227
The $category passed as the second param of getFields should not be the category id, but instead the category object itself. eg. in the blog.php override
This kind of question and answer can be found on the Joomla Stack Exchange, eg.
https://joomla.stackexchange.com/questions/23534/getting-categorys-custom-fields-in-a-blog-view