?
avatar denvarel
denvarel
4 Dec 2018

Steps to reproduce the issue

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 
?>

Expected result

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

Actual result

$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

System information (as much as possible)

Joomla 3.9.1
PHP 7.0.32 (but it does not work on another versions as well.

Additional comments

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.

avatar denvarel denvarel - open - 4 Dec 2018
avatar joomla-cms-bot joomla-cms-bot - change - 4 Dec 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 4 Dec 2018
avatar denvarel denvarel - change - 4 Dec 2018
The description was changed
avatar denvarel denvarel - edited - 4 Dec 2018
avatar denvarel denvarel - change - 4 Dec 2018
The description was changed
avatar denvarel denvarel - edited - 4 Dec 2018
avatar denvarel denvarel - change - 4 Dec 2018
The description was changed
avatar denvarel denvarel - edited - 4 Dec 2018
avatar denvarel denvarel - change - 4 Dec 2018
The description was changed
avatar denvarel denvarel - edited - 4 Dec 2018
avatar denvarel denvarel - change - 4 Dec 2018
The description was changed
avatar denvarel denvarel - edited - 4 Dec 2018
avatar JamesNGarrett
JamesNGarrett - comment - 8 Dec 2018

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

    $currentCatFields = FieldsHelper::getFields('com_content.categories', $this->category, true);
    echo '<pre>',print_r($currentCatFields,1),'</pre>';

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

avatar joomla-cms-bot joomla-cms-bot - change - 19 Dec 2018
Status New Closed
Closed_Date 0000-00-00 00:00:00 2018-12-19 17:25:41
Closed_By joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 19 Dec 2018
avatar Quy Quy - change - 19 Dec 2018
Closed_Date 2018-12-19 17:25:41 2018-12-19 17:25:43
Closed_By joomla-cms-bot Quy
avatar joomla-cms-bot
joomla-cms-bot - comment - 19 Dec 2018

Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/23227

Add a Comment

Login with GitHub to post a comment