0

I am creating Joomla 4 website powered by Zoo (CCK). In custom template I want to get the list of highligted topics in an article. The highlights are upto four. But the php code is fetching only the fisrt highlight. As well as I want to set one variable which list all the three highlights.

I have tried the below code:

<?php 
// get this list of all highlights of the article

foreach ($limeLights as $limeLight) {
     $highlight = '<li class="hlli">'.$limeLight['value'].'</li>';
}

// set variable for highlights element

$highlights     = '<div class="hlit">'
                  .'<h2 class="hliz">Highlights</h2><ul class="hlul">'
                  .''.$highlight.''
                  .'</ul></div>';
?>
<?php echo $highlights; ?>

The expected html output:

<div class="hlit">
<h2 class="hliz">Highlights</h2>
<ul class="hlul">
<li class="hlli">01. This is the first item from the list</li>
<li class="hlli">02. This is the second item from the list</li>
<li class="hlli">03. This is the third item from the list</li>
</ul>
</div>

But the html output I am getting:

<div class="hlit">
<h2 class="hliz">Highlights</h2>
<ul class="hlul">
<li class="hlli">01. This is the first item from the list</li>
</ul>
</div>
Dayyal Dg.
  • 50
  • 6
  • 1
    Try to change `$highlight =` to `$highlight .=` - you are currently overwriting the variable in your loop. So it does not matter how many you have, as there will be only one $limelight in there. – Uwe Dec 11 '22 at 22:31
  • If you work with concat, initialize the variable as an empty string. – Uwe Dec 11 '22 at 22:41
  • If you want to clean-up your code, you could move some html to outside of the php tags as well. For expample: https://onlinephp.io/c/f18a6 – Uwe Dec 11 '22 at 22:43

1 Answers1

0

You can rearrange the code a bit to do it all as one string:

$highlights      = '<div class="hlit">'
                  .'<h2 class="hliz">Highlights</h2><ul class="hlul">';

foreach ($limeLights as $limeLight) {
    $highlights .= '<li class="hlli">'.$limeLight['value'].'</li>';
}

$highlights     .= .'</ul></div>';
Sammitch
  • 30,782
  • 7
  • 50
  • 77