In my custom component, I use a repeatable field.
Sometimes it is possible that a url_partenaire
element is an empty string because it is not mandatory.
var_dump($this->item->logo_repeatable_list)
gives this:
string(157) "{
"logo":
["images/website_logo_1.png","images/website_logo_2.png","images/website_logo_3.png"],
"url_partenaire":
["","https://www.url_website_2.fr",""]
}"
I need to create this:
<img src="images/website_logo_1.png">
<a href="https://www.url_website_2.fr"><img src="images/website_logo_2.png"></a>
<img src="images/website_logo_3.png">
I begin with this, but it works only if there is one field in the repeatable field:
<?php
$jsonPartenaires = json_decode($this->item->logo_repeatable_list, true);
?>
<?php foreach ($jsonPartenaires as $key => $value) {
foreach ($value as $content) echo '<img src="'. $content . '">';
}
?>
I don't really know what to do now.