Created
January 30, 2012 21:28
-
-
Save warrenbuckley/1706821 to your computer and use it in GitHub Desktop.
Umbraco V5 Example - Media Picker List Images from Folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got it!