Joomla Asked by Semaphore on September 5, 2021
I’m trying to get the custom fields value of a category in a blog view.
I have try the article item method but on the child item (supposed to be the current category item in the loop) :
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
then in the loop
<?php foreach ($this->children[$this->category->id] as $id => $child) : ?>
<?php foreach($child->jcfields as $jcfield)
{
$child->jcFields[$jcfield->name] = $jcfield;
}
and then
<?php echo "test:".$child->jcFields['titre-discipline']->label; ?>
but i get nothing, no error, nothing. One the category actually get value in. THe custom show correctly in the category item view but not in this blog view.
Thanks for your help
Load the fields with FieldsHelper::getFields()
. This allows to access each field individually by its name.
<?php foreach(FieldsHelper::getFields('com_content.categories', $child) as $field) : ?>
<?php $child->jcFields[$field->name] = $field; ?>
<?php endforeach; ?>
<?php echo "test:".$child->jcFields['titre-discipline']->label; ?>
If you just want to render the fields using the standard layout, use FieldsHelper::render()
instead:
<?php echo FieldsHelper::render(
'com_content.categories',
'fields.render',
array('context' => 'com_content.categories', 'item' => $child, 'fields' => FieldsHelper::getFields('com_content.categories', $child))
); ?>
Answered by Sharky on September 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP