I'm trying to create an override for my template to customize the way an extension should display it's fields in the article.
The extension I use is DPfields and I'm using this reference guide from the developer: https://joomla.digital-peak.com/documentation/162-dpfields/2750-rendering-fields
Expecially I'm referencing to the paragraph: Accessing the fields in the layout
I've created a new php file started from the default.php file for article view and inside this new file (newfile.php) I'm trying to display a gallery field type from the component DPField.
I've succesfully inserted this code in the newfile.php:
<?php
foreach ($this->item->dpfields as $field) {
$gallery = (($field->type)=='gallery');
if (!empty($gallery)) {
echo '<div class="galleryfield">' .$field->value. '</div>';
}
}
?>
so it correctly shows in the output the gallery.
My question is: how could I improve that code? Is there a better way to let it work instead of using a foreach?
Thanks in advance.