Skip to content

Instantly share code, notes, and snippets.

@warrenbuckley
Created January 30, 2012 21:28
Show Gist options
  • Save warrenbuckley/1706821 to your computer and use it in GitHub Desktop.
Save warrenbuckley/1706821 to your computer and use it in GitHub Desktop.
Umbraco V5 Example - Media Picker List Images from Folder
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@{
//Output an image from the media picker
//Property alias of mediaPicker
var mediaPickerPropAlias = String.IsNullOrEmpty(Model.MacroParameters.mediaPickerPropAlias) ? "myMediaPickerPropertyAlias" : Model.MacroParameters.mediaPickerPropAlias;
//Check that the property has a hiveID stored
if (!String.IsNullOrEmpty(DynamicModel[mediaPickerPropAlias]))
{
//Get the mediaFolder
var mediaFolder = Umbraco.GetDynamicContentById(DynamicModel[mediaPickerPropAlias]);
foreach (var mediaItem in mediaFolder.Children)
{
//Get the image URL
//The HiveID of the selected media item from the media picker
//Then the string property alias of the upload data type on the media type
var imageURL = Umbraco.GetMediaUrl(mediaItem.Id, "uploadedFile");
//Get the name of the media item
var mediaName = mediaItem.Name;
<img src="@imageURL" alt="@mediaName" />
}
}
else
{
<p>No media HiveID present</p>
}
}
Copy link

ghost commented Feb 22, 2012

Got it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment