Jump to content

Repeater, check to see if the repeated element is first.


quickjeff
 Share

Recommended Posts

Hi Guys, 

I have created a slider using Bootstrap and in Bootstrap the slider image that is first in line is required to have the class active.  In creating a repeater for my client to add images, I need to add a conditional statement to check if the item is first in the repeated elements and if it indeed is first, assign active as the class. 

Not sure what is best practice using a selector and the api to see if the the repeated element is first in the repeater list.

Any light?

Thanks guys!

Link to comment
Share on other sites

If I understand correctly, the usual approach is to use a counter inside your foreach.

$i=0;
foreach($sliderimage as $image){
    echo '<img ' . ($i==0 ? 'class="active"' : '') . ' src="{$image->url}" />';
    $i++;
}

Or something along those lines.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...