@foreach (var thisSku in skuList) {
if (thisSku.HasValue("productImages")) {
var productImagePicker = thisSku.GetPropertyValue<IEnumerable<IPublishedContent>>("productImages");
if(thisSku.IsFirst()){
<p>hello0</p>
foreach(var productImage in productImagePicker) {
//<p>hello3</p>
if(productImage.IsFirst()){
<p>hello1</p>
}
}
} else {
foreach(var productImage in productImagePicker) {
if(productImage.IsFirst()){
<p>hello2</p>
}
}
}
}
}
It is totally doing my head in as there are the same images in each image picker. If I uncomment hello3 I get many hello3s, but can't show just the first one.
"because of some issues in IPublishedContent, IsFirst, IsOdd, Index... all gave random results as soon as contents was not the origin children collection. this has been fixed but requires the usage of the .ToContentSet() method"
Nested IsFirst()
Umb 7.2.2
The code below should produce:-
Hello0
Hello1
Hello2
But it always produces:-
Hello0
Hello2
@foreach (var thisSku in skuList) { if (thisSku.HasValue("productImages")) { var productImagePicker = thisSku.GetPropertyValue<IEnumerable<IPublishedContent>>("productImages"); if(thisSku.IsFirst()){ <p>hello0</p> foreach(var productImage in productImagePicker) { //<p>hello3</p> if(productImage.IsFirst()){ <p>hello1</p> } } } else { foreach(var productImage in productImagePicker) { if(productImage.IsFirst()){ <p>hello2</p> } } } } }
It is totally doing my head in as there are the same images in each image picker. If I uncomment hello3 I get many hello3s, but can't show just the first one.
Is there a bug with nested .IsFirst()?
Any advice appreciated.
Craig
Well in the end I had to resort to a counter. I feel dirty....
HTH someone else,
Craig
Hi Craig,
Give this a try
Jeavon
Thanks Jeavon, I'm clean again :)
Googling on "ToContentSet" brings up this link: https://gist.github.com/zpqrtbnk/6582377, with a handy reason for the issue in the comments:-
"because of some issues in IPublishedContent, IsFirst, IsOdd, Index... all gave random results as soon as contents was not the origin children collection. this has been fixed but requires the usage of the .ToContentSet() method"
Craig
is working on a reply...