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
I want to write in a partial view, a dynamic carousel that pulls images from a selected folder.
I'm struggling to find how you do this in v9 and the sort of code I'd have used in v7 obviously doesn't work with all the changes.
Has anyone got a simple example of how you do this in v9 please?
Hi Steve
If you create a 'Media Picker' on a document type that is only allowed to pick one Folder, and give it alias 'carouselFolder'
Then the following in a partial view would read the folder, and loop through it's children:
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage @using Umbraco.Cms.Core @using Umbraco.Cms.Core.Models.PublishedContent @using Umbraco.Cms.Core.Routing @using Umbraco.Extensions @inject IPublishedUrlProvider PublishedUrlProvider @{ var mediaFolder = Model.Value<IPublishedContent>("carouselFolder"); var selection = mediaFolder.Children(); } @if (selection!=null && selection.Any()) { <ul> @foreach (var item in selection) { <li> <a href="@item.Url(PublishedUrlProvider)"> <img src="@Url.GetCropUrl(item,height: 50, width: 50)" /> <br />@item.Name</a> </li> } </ul> }
Broadly speaking this is the same as V8... or you may be using ModelsBuilder in which case
mediaFolder = Model.CarouselFolder;
would I think also work
so GetCropUrl is still the way to get a crop of an image that you have retrieved the IPublishedContent representation of.
the only difference is injecting the PublishedUrlProvider into the Url() method... but I think that has been updated to work without it too...
regards
marc
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Accessing media files in a partial view
I want to write in a partial view, a dynamic carousel that pulls images from a selected folder.
I'm struggling to find how you do this in v9 and the sort of code I'd have used in v7 obviously doesn't work with all the changes.
Has anyone got a simple example of how you do this in v9 please?
Hi Steve
If you create a 'Media Picker' on a document type that is only allowed to pick one Folder, and give it alias 'carouselFolder'
Then the following in a partial view would read the folder, and loop through it's children:
Broadly speaking this is the same as V8... or you may be using ModelsBuilder in which case
would I think also work
so GetCropUrl is still the way to get a crop of an image that you have retrieved the IPublishedContent representation of.
the only difference is injecting the PublishedUrlProvider into the Url() method... but I think that has been updated to work without it too...
regards
marc
is working on a reply...