0

I have category custom fields and I need to show these in the article (which is in the category) view.

I have used the following:

use Joomla\CMS\Factory; use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; // Get the category object $customFields = FieldsHelper::getFields('com_content.category', $category, true); var_dump($customFields); 

This outputs as:

array(0) { } 

I need to output the custom fields. I have even tried the following

 <div class="custom_fields"> <?php foreach ($customFields as $catfield) { echo '<div>'; echo '<h3>' . htmlspecialchars($catfield->label) . '</h3>'; echo '<p>' . htmlspecialchars($catfield->value) . '</p>'; echo '</div>'; } ?> </div> 

but it's only outputting as:

<div class="custom_fields"></div> 
1
  • This code is incomplete. How are you getting the category object? Commented Dec 8, 2023 at 8:52

1 Answer 1

0

For debugging that, I use :

<?php echo "<pre>"; print_r($customFields); echo "</pre>"; ?> <?php foreach ($customFields as $catfield) { echo '<div>'; echo '<h3>' . htmlspecialchars($catfield) . '</h3>'; echo '</div>'; } ?> </div> 

So, now you can see the content of the object with the properties you want. After that, you can user $catfield->YOURPROPERTIE

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.