Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Iterating through a foreach loop, can we detect the first iteration by using First(), without setting a counter as in:-
@{ //Check there are slider image page loaded var theCount = @Model.Descendants("SliderImagePage").Count(); if (theCount > 0) { foreach (var theImagePage in Model.Descendants("SliderImagePage")) { var theImage = theImagePage.Media("sliderImage","umbracoFile"); if (theImagePage.First() == true) { @:<div class="slide" style="background-image:url('@Html.Raw(theImage)');display:block;"></div> } else { @:<div class="slide" style="background-image:url('@Html.Raw(theImage)');display:none;"></div> } } } else { @: No Picture Image pages set up } }
The above doesn't work but I can't work out how it should.
The site is Umbraco V4.7.2
Any pointers would be helpful.
Thanks
Craig
Hi Craig,
How weird i just posted a solution of mine a few minutes before where i was looking for the Last() item in media folder.
My solution as
if(img.IsLast()){//do something}
Have you try if(theImagePage.IsFirst()){}
Did you have a look at the Razor Dynamic Cheat Sheet?
Thanks, that worked:)
I have the cheat sheet printed out here right now, but didn't see the IsHelpers section! This is the problem with dipping in and out of various technologies during the day :(
Cheers,
Glad you got this working.
//fuji
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Razor use of First()
Iterating through a foreach loop, can we detect the first iteration by using First(), without setting a counter as in:-
The above doesn't work but I can't work out how it should.
The site is Umbraco V4.7.2
Any pointers would be helpful.
Thanks
Craig
Hi Craig,
How weird i just posted a solution of mine a few minutes before where i was looking for the Last() item in media folder.
My solution as
Did you have a look at the Razor Dynamic Cheat Sheet?
Thanks, that worked:)
I have the cheat sheet printed out here right now, but didn't see the IsHelpers section! This is the problem with dipping in and out of various technologies during the day :(
Thanks
Cheers,
Craig
Hi Craig,
Glad you got this working.
//fuji
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.