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
Hi Guys,
Can someone point out how to Display the first 5 images from a Media Picker and the remaining "x" amount to get only the url.
I know how to get this done in XSLT but how to achieve this in Razor?
@foreach(dynamic img in items){ <span> <a href="@img.Url" rel="prettyPhoto[@Model.NodeTypeAlias]"><img src="@(img.UmbracoFile.Replace(".jpg","_thumb.jpg"))" width="100" height="100"/></a></span> }
if i make use of items.Take(5) it will obviously display only 5 items and thus limiting my slideshow to 5 instead of "x" amount .
What should the output HTML look like?
Use Skip() after Take() and you should be fine:
foreach (dynamic img in items.Take(5)){ <span> <a href="@img.umbracoFile" rel="prettyPhoto[@Model.NodeTypeAlias]"><img src="@(img.umbracoFile.Replace(".jpg", "_thumb.jpg"))" alt="" width="100" height="100" /></a></span>} foreach (dynamic img in items.Skip(5)){ <span><a href="@img.umbracoFile" rel="prettyPhoto[@Model.NodeTypeAlias]">@img.Name</a></span>}
Hi Douglas,
Thanks for the help. It worked indeed. I was thinking may be this could be done like xslt instead of having do make 2 foreach loops.
More of something like
<choose><when></when><otherwise></otherwise></choose>
//fuji
Hi Fuji,
You could also use a good ol' for loop to avoid looping through the list two times:
// Can't remember if the Count is a property or a method: Count();for(int i = 0; i < items.Count; i++){ dynamic img = items[i]; <span><a href="@img.UmbracoFile" rel="prettyPhoto[@Model.NodeTypeAlias]"> @if(i <= 5) { <img src="@(img.umbracoFile.Replace(".jpg", "_thumb.jpg"))" alt="" width="100" height="100" /> } </a> </span>}
Above example is untested.
Another thing is, that I'm not sure if it's "legal" in W3C terms to have a <img /> tag inside of a <span> tag, but that's a-whole-nother story ;-)
Let me know how this works.
All the best,
Bo
Hi Bo,
Thanks for the reply and help. Unfortunately this didnt work for me.
I will keep it as such for the time being and whenever i gave some spare time i will try to make use of @helper to achieve and get the same results.
Hmm, alright, but out of curiousity: where did it fail in my code snippet?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Displaying only 5 Images and the remaining x amount only url
Hi Guys,
Can someone point out how to Display the first 5 images from a Media Picker and the remaining "x" amount to get only the url.
I know how to get this done in XSLT but how to achieve this in Razor?
if i make use of items.Take(5) it will obviously display only 5 items and thus limiting my slideshow to 5 instead of "x" amount .
What should the output HTML look like?
Use Skip() after Take() and you should be fine:
Hi Douglas,
Thanks for the help. It worked indeed. I was thinking may be this could be done like xslt instead of having do make 2 foreach loops.
More of something like
//fuji
Hi Fuji,
You could also use a good ol' for loop to avoid looping through the list two times:
Above example is untested.
Another thing is, that I'm not sure if it's "legal" in W3C terms to have a <img /> tag inside of a <span> tag, but that's a-whole-nother story ;-)
Let me know how this works.
All the best,
Bo
Hi Bo,
Thanks for the reply and help. Unfortunately this didnt work for me.
I will keep it as such for the time being and whenever i gave some spare time i will try to make use of @helper to achieve and get the same results.
//fuji
Hi Fuji,
Hmm, alright, but out of curiousity: where did it fail in my code snippet?
is working on a reply...