How do I display the custom field value in the Site Modules?
Moderators: ooffick, General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
-
- Joomla! Apprentice
- Posts: 7
- Joined: Fri Apr 22, 2022 3:41 am
How do I display the custom field value in the Site Modules?
Hello,I have a problem, and need help.Thank you.
I haved create a custom category field called "CatIcon", and how do I display the custom field value of "CatIcon" when retrieving the article category list on the website homepage?
I want to output the values of the custom field "CatIcon" in the attachment of the 4 screenshot. The PHP file is: default-20230922-023726. php. Who can help me write the code for the field ivalue in the Site Modules.Thanks.
I haved create a custom category field called "CatIcon", and how do I display the custom field value of "CatIcon" when retrieving the article category list on the website homepage?
I want to output the values of the custom field "CatIcon" in the attachment of the 4 screenshot. The PHP file is: default-20230922-023726. php. Who can help me write the code for the field ivalue in the Site Modules.Thanks.
You do not have the required permissions to view the files attached to this post.
Last edited by toivo on Fri Sep 22, 2023 3:11 am, edited 1 time in total.
Reason: mod note: moved from 4.x General Questions
Reason: mod note: moved from 4.x General Questions
- Pavel-ww
- Joomla! Ace
- Posts: 1413
- Joined: Tue Jun 30, 2020 12:17 pm
Re: How do I display the custom field value in the Site Modules?
Hi. The code on your screenshot does not look like the right override of Categories list Module [mod_articles_categories].
You always need to use two files.
default.php - This is the shell calling the list of categories. --
default_items.php - This is a list of categories that are called in the shell. --
For the output of category custom fields, you should edit default_items.php, by adding the following parts of the code to it: --
Code: Select all
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
<?php $customFields = FieldsHelper::getFields('com_content.categories', $item, true);
foreach ($customFields as $customField) {
$customFields[$customField->name] = $customField;
} ?>
<span><?php echo $customFields['my-field']->value ?></span>
If you want to rename the module php template you should rename both files (for example to custom.php and custom_items.php ) and also you should to change it in the code, in both files.
You do not have the required permissions to view the files attached to this post.
Last edited by Pavel-ww on Tue Sep 26, 2023 3:58 pm, edited 1 time in total.
- Pavel-ww
- Joomla! Ace
- Posts: 1413
- Joined: Tue Jun 30, 2020 12:17 pm
Re: How do I display the custom field value in the Site Modules?
Here is the result output
You do not have the required permissions to view the files attached to this post.
-
- Joomla! Explorer
- Posts: 285
- Joined: Tue Feb 17, 2015 10:25 am
Re: How do I display the custom field value in the Site Modules?
Code: Select all
$getFields = FieldsHelper::getFields('com_content.categories', $this->category, true);
$fields = ArrayHelper::pivot($getFields , 'name');
echo $fields['CatIcon’']->rawvalue
- Pavel-ww
- Joomla! Ace
- Posts: 1413
- Joined: Tue Jun 30, 2020 12:17 pm
Re: How do I display the custom field value in the Site Modules?
Hi @erick-b. I think if you provide a solution, then it must be a worker. Otherwise, the forum will turn into a dump of garbage. Your solution does not work for two reasons.erick-b wrote: ↑Wed Sep 27, 2023 8:30 am;Code: Select all
$getFields = FieldsHelper::getFields('com_content.categories', $this->category, true); $fields = ArrayHelper::pivot($getFields , 'name'); echo $fields['CatIcon’']->rawvalue
1) It is necessary to connect ArrayHelper
2) $this->category does not work in the module. Instead should be used $item
We are talking about the Categories List Module here [mod_articles_categories]
-
- Joomla! Explorer
- Posts: 285
- Joined: Tue Feb 17, 2015 10:25 am
Re: How do I display the custom field value in the Site Modules?
Code: Select all
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
use Joomla\Utilities\ArrayHelper;
Fields = FieldsHelper::getFields('com_content.categories', $this->category, true);
$fields = ArrayHelper::pivot($getFields , 'name');
echo $fields['CatIcon’']->rawvalue
instead of $this->category use $item , $this->item ... or whatever is already present in your code
-
- Joomla! Explorer
- Posts: 285
- Joined: Tue Feb 17, 2015 10:25 am
- Pavel-ww
- Joomla! Ace
- Posts: 1413
- Joined: Tue Jun 30, 2020 12:17 pm
Re: How do I display the custom field value in the Site Modules?
It is funny that if someone tries this code and is convinced that it does not work, you will lose a reputation, instead of self-affirmation (which is apparently your goal).erick-b wrote: ↑Wed Sep 27, 2023 6:26 pmCode: Select all
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; use Joomla\Utilities\ArrayHelper; Fields = FieldsHelper::getFields('com_content.categories', $this->category, true); $fields = ArrayHelper::pivot($getFields , 'name'); echo $fields['CatIcon’']->rawvalue

That "stupid foreach" is an universal solution for all cases, if you have more than one field for example.
Did you intend to make typos so that this code does not work for a non -professional? Here people ask for help actually, and not measured skills. If you are not ready to be "his mother", then this forum is not for you (IMO).
-
- Joomla! Explorer
- Posts: 285
- Joined: Tue Feb 17, 2015 10:25 am