Different template for first item

Posted by Manda Shafer on 27-Aug-2019 20:55

I have created a custom module called "Slider". I would like to create an mvc view where the first item shows the picture, title, description, and url (all fields in the custom module), but has a different format for the remaining items.

Is there a way to do a @foreach (var item in Model.Items) for just the first, and then something else for the rest?

All Replies

Posted by JGraham@edgewood.edu on 27-Aug-2019 21:15

You could add a counter for the forEach and put the conditional on if it's a count of 1.   Also, depending on what you're changing maybe handle it with CSS and a :first-child selector.    

Both are pretty low tech, but likely could work.

This thread is closed