T
T
Tlegen Bayangali2018-07-28 12:39:54
Joomla
Tlegen Bayangali, 2018-07-28 12:39:54

How to add additional fields in Joomla?

The task is to set additional fields manually.

<?php 
// GET CUSTOM FIELDS
    $myCustomFields = array();
    foreach($this->item->jcfields as $field) {
        $myCustomFields[$field->name] = $field->value;
} 
// RECOVER CUSTOM FILED NAME
    if (isset($myCustomFields['field-1']) and !empty($myCustomFields['field-1'])) : ?>
        <div class="field">
            <div class="field__name">Название поля:</div>
            <div class="field__value"><?php echo $myCustomFields['field-1']; ?></div>
        </div>
<?php endif; ?>

there are no problems with displaying additional fields directly in the article.php template.
but I need to output them to the blog category template. An error occurs when trying to display a field.
Warning: Invalid argument supplied for foreach() in C:\OpenServer\domains\center-skidok.loc\templates\centerskidok\html\com_tags\tag\default_items.php on line 65

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2018-08-16
@Starina_js

This is not a blog category template. It is you who are trying to display the fields from the materials in the "labels" component, so they are not there.
This is how you can

JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$item->jcfields = FieldsHelper::getFields('com_content.article', $item, true);
$fields = [];
foreach($item->jcfields as $jcfield)
{
  $fields[$jcfield->name] = $jcfield;
}
$fields['имя_поля']->rawvalue;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question