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?
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:
@inject IPublishedUrlProvider PublishedUrlProvider
var mediaFolder = Model.Value<IPublishedContent>("carouselFolder");
var selection = mediaFolder.Children();
@if (selection!=null && selection.Any())
@foreach (var item in selection)
<img src="@Url.GetCropUrl(item,height: 50, width: 50)" />
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...
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted