Created
January 30, 2012 16:55
-
-
Save warrenbuckley/1705409 to your computer and use it in GitHub Desktop.
Umbraco V5 Example - Media Picker
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 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(DynamicModel[mediaPickerPropAlias], "uploadedFile"); | |
//Get the name of the media item | |
var mediaName = Umbraco.GetDynamicContentById(DynamicModel[mediaPickerPropAlias]).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
@pepeortiz yes that is also correct but your method is using an Image Upload field with the alias yourImagePropertyName on the current document type.
The way above is using a media tree picker property on the current document type which has the alias of picture which stores the ID to the media item stored in the media section. If an image node from the media section was selected then it has a property on that media type which is an upload field which has the property alias of uploadedField
I hope this makes sense the two different approaches.
One is for an upload field on the current document type and the other is using a media picker on the document type