mod_articles module
If you want to include custom fields that do not display automatically in an article, they won't display.
Further info: I have a category for an annual concert series that is composed entirely of fields, e.g. date, time, location, concert info, ticket price, Youtube links, etc., none of which display automatically in the article editing area. Each field has its own CSS style and some have related JS. This means that the information is displayed in a consistent way across each article and (non-admin, on the front) editors can be sure to put the right information in the right place. The concerts are shown in a blog and also in modules created from mod_articlescategory overrides showing selected fields.
I discovered yesterday that something has happened so that a module from a previous concert season displayed on a newly created menu item only shows the article title - but three fields on the original page - which made me think that something has changed in the mod_articlescategory module, so I started to create a new module override from the mod_articles module.
Simply adding the html for the fields didn't work. See example of code:
<div class="concert-date"><?php $customFields = FieldsHelper::getFields('com_content.article', $item, true);
$values = array_column($customFields, 'value', 'name');
echo $values['concert-long-date-and-time']; ?></div>
But, having added the line of FieldsHelper code as below the new module now displays the fields as expected.
Simply add
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
to line 16 in /templates/[template-name]/html/mod_articles/default_items.php
None
| Labels |
Added:
No Code Attached Yet
|
||
@richard67 I undeerstand what you are saying but you should really be able to display an articles custom fields when the article is displayed in a module. Maybe this code proposal is not perfect/correct but the missing functionality is a real world problem that needs to be resolved
Does that mean that in the old legacy mod_articles_category it was working, and in the new mod_articles not?
Does that mean that in the old legacy mod_articles_category it was working, and in the new mod_articles not?
Yes. But only partially. All the ones I am concerned about are module overrides that I created a few years ago. Modules that I created last season display correctly but in one case I made a copy of a module and changed the category and then only the titles appeared. The category was simply a change from 2024-25 to 2025-26 within the same 'Season' parent category. All fields etc are the same.
Also, when I created a new module using my existing legacy mod_articles_category override, it had the same issue - the fields didn't display. I had changed nothing in the code prior to today.
Which is why I thought I'd better try out the new mod_articles module instead.
If you want to use it in an override, you can use the full qualified class name. In your example code this would be:
<div class="concert-date"><?php $customFields = Joomla\Component\Fields\Administrator\Helper\FieldsHelper::getFields('com_content.article', $item, true); $values = array_column($customFields, 'value', 'name'); echo $values['concert-long-date-and-time']; ?></div>Does that help?
I changed my override so all fields were requested as above. It worked... until I removed the
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
and then I just got a blank white screen, losing everything on the page.
And when I used mod_articles_news I used to add fields like this:
<div class="concert-date"><?php echo $item->jcfields[25]->value; ?></div>
So simple, but it doesn't work in the new mod_articles
@Scrabble96 The core file does not use the FieldsHelper, so adding an include (
use) statement to the code file would result in an unusedusestatement, which violates our code style.If you want to use it in an override, you can use the full qualified class name. In your example code this would be:
Does that help?