Built in Gallery Scripts to Render out Cropped Media
Hi.
I'm trying to setup an image gallery using the built in scripts but am having some issues getting the image urls populated in the image tag. The default set up works fine but I've changed the Media section to upload images via a cropper so that the editors can do their own image manipulation.
Unfortunately this means that the default Gallery scripts returns full cropper data which isn't any good. I've tried using the following code to address the crop I'm after but this just returns a blank src="".
@inherits umbraco.MacroEngines.DynamicNodeContext
@*
Macro to display a gallery from a media folder. Add the below parameter to the macro
and use it to point the macro at a specific media folder to display it's content as
a simple list.
Macro Parameters To Create, for this macro to work:
Alias:mediaId Name:Media Folder ID Type:Single Media Picker
*@
@if (Parameter.mediaId != null)
{
@* Get the media folder as a dynamic node *@
var mediaFolder = Library.MediaById(Parameter.mediaId);
if (mediaFolder.Children.Any())
{
<ul class="thumbnails">
@* for each item in children of the selected media folder *@
@foreach (var mediaItem in mediaFolder.Children)
{
var cropUrl = mediaItem.GetCropUrl("umbracoFile", "thumb");
<li class="span2">
<a href="@cropUrl.umbracoFile" class="thumbnail">
<img src="@cropUrl" alt="@mediaItem.Name" />
</a>
</li>
}
</ul>
}
}
Any pointers to where I'm going wrong would be great.
I think that you are missing one little thing. I assume that you link to the file works well, and therefore in the image tag where you call the url to the image you also need to add umbracoFile, to get the path to the image.
Try to see the uHangout EP030 - Jeavon Leopold episode of uHangout where Jeavon talks about the image cropper and how to configure it. http://uhangout.co.uk/video/bQsvGmnYaUU
Built in Gallery Scripts to Render out Cropped Media
Hi.
I'm trying to setup an image gallery using the built in scripts but am having some issues getting the image urls populated in the image tag. The default set up works fine but I've changed the Media section to upload images via a cropper so that the editors can do their own image manipulation.
Unfortunately this means that the default Gallery scripts returns full cropper data which isn't any good. I've tried using the following code to address the crop I'm after but this just returns a blank src="".
@inherits umbraco.MacroEngines.DynamicNodeContext
@*
Macro to display a gallery from a media folder. Add the below parameter to the macro
and use it to point the macro at a specific media folder to display it's content as
a simple list.
Macro Parameters To Create, for this macro to work:
Alias:mediaId Name:Media Folder ID Type:Single Media Picker
*@
@if (Parameter.mediaId != null)
{
@* Get the media folder as a dynamic node *@
var mediaFolder = Library.MediaById(Parameter.mediaId);
if (mediaFolder.Children.Any())
{
<ul class="thumbnails">
@* for each item in children of the selected media folder *@
@foreach (var mediaItem in mediaFolder.Children)
{
var cropUrl = mediaItem.GetCropUrl("umbracoFile", "thumb");
<li class="span2">
<a href="@cropUrl.umbracoFile" class="thumbnail">
<img src="@cropUrl" alt="@mediaItem.Name" />
</a>
</li>
}
</ul>
}
}
Any pointers to where I'm going wrong would be great.
Cheers
Chris
Hi Chris and welcome to our.
I think that you are missing one little thing. I assume that you link to the file works well, and therefore in the image tag where you call the url to the image you also need to add umbracoFile, to get the path to the image.
So your image tag would look like this:
And your hole script block would look like this:
Try to see the uHangout EP030 - Jeavon Leopold episode of uHangout where Jeavon talks about the image cropper and how to configure it. http://uhangout.co.uk/video/bQsvGmnYaUU
Hope this helps,
/Dennis
is working on a reply...