0
votes

I'm trying to create a layout view for Joomla Articles to customize the way fields of Component DP Fields are rendered in my layouts.

I've created a new file in /templates/mytemplate/html/com_content/article/progetti.php (that is a copy of default.php)

Here I'm trying to put this code (see reference here: [https://joomla.digital-peak.com/documentation/162-dpfields/2750-rendering-fields][1]):

if (! key_exists('field', $displayData))
{
    return;
}

$field = $displayData['field'];
$label = $field->label;
$value = $field->value;
if (! $value)
{
    return;
}

$class = $field->render_class;
?>

<dd class="dpfield-entry <?php echo $class;?>">
    <span class="dpfield-label"><?php echo htmlentities($label);?>: </span>
    <span class="dpfield-value"><?php echo $value;?></span>
</dd>

Anyway in this case I've got some errors:

Notice: Undefined variable: displayData in /home/.../.../.../templates/mytemplate/html/com_content/article/progetti.php on line 112

Warning: key_exists() expects parameter 2 to be array, null given in /home/.../.../.../templates/mytemplate/html/com_content/article/progetti.php on line 112

I want to display DPFields' fields in the article customizing the layout. What should I do to correctly let it work?

1

1 Answers

0
votes

You don't have $displayData object inside of your article template. If you want to access that fields from your article template then try this code:

foreach ($this->item->dpfields as $field) {
    echo '<li><b>'.$field->label.'</b>'.$field->value.'</li>';
}

Even if this won't help, then just output your view object by

print_r($this)

And in which variable inside of view you can see your DP Fields.