0

How do I query the joomla custom field group and its content (if it exists)? I want the content of field groups to be "implemented" in the joomla's template com_content/article/default.php file. My basic concept already exists, I want to see the contents of each group under different tabs. I could ask about the content of the fields, but unfortunately I can not access the field groups. Can somebody give me some help in this? Thanks in advance!

(In my example I'm not interested of the user groups.)

For example: I have created three field groups with different fields. (in this example only the field group names are listed, Field group 1, Field group 2, Field group 3). I would like to display the content of the field groups: (Field group 1 content, Field group 2 content, Field group 3 content)

<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item">
    <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Field group 1</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Field group 2</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Field group 3</a>
  </li>
</ul>
<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">Field group 1 content</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">Field group 2 content</div>
  <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">Field group 3 content</div>
</div>
2
  • Are you asking how to construct the query? or how to implement the query that does the job? Commented Dec 16, 2018 at 12:57
  • I want to display the result. No matter whether it is a database query or a query of fields.php. Tthe second might be faster.
    – Tomy70
    Commented Dec 16, 2018 at 13:20

1 Answer 1

1
// GET YOUR CUSTOM FIELDS

$myCustomFields = array();
    foreach($this->item->jcfields as $field) {
        $myCustomFields[$field->name] = $field->value; } 

// Value of Custom Field with the Field Name "Custom_Field_Content"

$Custom_Field_Content = $myCustomFields['Custom_Field_Content'];

Now you can use PHP to insert the Value

<?php if (!empty($Custom_Field_Content)) echo $Custom_Field_Content; ?>
4
  • 1
    Thanks for your job, KlintWeb. But this is not what i need. For your result you need <?php JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); ?> too because you must register Joomla's fields.php file too. What i need is a separeted/categorized list of the field values.
    – Tomy70
    Commented Dec 16, 2018 at 19:41
  • Turn it into an array and order by group?
    – Eoin
    Commented Dec 17, 2018 at 22:45
  • You don't need anything else, if you makes an override in Joomla's template com_content/article/default.php
    – KlintWeb
    Commented Dec 17, 2018 at 22:54
  • KlintWeb you're right. I apologize for my ignorance. First I created an overwrite, but I did not even watch the line at the beginning of the file, which already registers/calls the helpers. It's almost done. If I have it, will share it.
    – Tomy70
    Commented Dec 19, 2018 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.