With Joomla 3.7.x article custom fields have finally gotten part of Joomla content.
However, I would like to ask how I can render these Custom Fields in the Joomla Category List?
Adding custom fields to the Joomla Category List is still not part of Joomla (hopefully it will come one day too).
So in order to add the custom fields to the Joomla Category List, I've made an template override of 'com_content/category/default_articles.php' to add two columns that I want to use to display Two Custom fields:
- Date field with Title: 'Entry into force' and name 'gildiskoma'
- Text field with Title 'Type' and name 'slag'
My current override of default_articles.php looks like this:
<?php /**--- Enable direct access by name to custom fields (Top) ----*/ ?>
<?php foreach($item->jcfields as $jcfield)
{
$item->jcFields[$jcfield->name] = $jcfield;
}
?>
<?php /**--------- Custom Fields Header (Around line 120) -----------*/ ?>
<?php if ($this->params->get('list_show_votes')) : ?>
<th id="categorylist_header_dato">
<?php echo JHtml::_('grid.sort', 'LIST_GILDISKOMA', 'gildiskoma', $listDirn, $listOrder); ?>
</th>
<?php endif; ?>
<?php if ($this->params->get('list_show_votes')) : ?>
<th id="categorylist_header_type">
<?php echo JHtml::_('grid.sort', 'LIST_SLAG', 'slag', $listDirn, $listOrder); ?>
</th>
<?php endif; ?>
<?php /**--- Custom Category List Fields Content (Around line 250) ---*/ ?>
<?php if ($this->params->get('list_show_votes', 0) && $this->vote) : ?>
<td headers="categorylist_header_date" class="list-gildiskoma">
<?php echo $item->jcFields['gildiskoma']->value; ?>
</td>
<?php endif; ?>
<?php if ($this->params->get('list_show_votes', 0) && $this->vote) : ?>
<td headers="categorylist_header_type" class="list-slag">
<?php echo $item->jcFields['slag']->value; ?>
</td>
<?php endif; ?>
We don't use the article vote feature, so I've chosen to use the Custom Fields in its place as you might notice from the code above, which gives me two custom columns.
I've looked at the documentation for J3.x:Adding custom fields/Overrides and also found this post on How to fetch Joomla article custom fields in another component?
The documentation has a section explaining how to add individual fields with override. But my code above doesn't display the custom fields value.
So I'm not sure what I'm missing to get the fields value to show in the list?
Below also a screenshot which illustrates what I'm trying to do.