Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dan 54 posts 133 karma points
    Aug 03, 2014 @ 07:05
    dan
    0

    Media Picker as a Generic Property on a Template

    Hi All,

    I have a media picker as one of my generic properties on a template page. I'm trying to get the file path to the image selected but I cannot figure out how to do this from any of the examples I've found. I can get all the other generic properties by simply calling @CurrentPage.someproperty to get a value. I can't do the same with a media picker. I only have the one on the page so can some one please help me do this?

    version 7.1.4

    Thanks,

     

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "umbLayout.cshtml";
    }
    @Umbraco.RenderMacro("InsertWidgit", new {mediaFile="[no clue how to access this from the media picker]", [email protected], [email protected]})

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 03, 2014 @ 11:08
    Jeavon Leopold
    1

    Hi Dan,

    Something like this:

    @{      
        if (CurrentPage.HasValue("yourMediaPickerAlias")){                                         
            var dynamicMediaItem = Umbraco.Media(CurrentPage.yourMediaPickerAlias);
            <img src="@dynamicMediaItem.Url" alt="@dynamicMediaItem.Name"/>
        }
    }
    

    Jeavon

  • dan 54 posts 133 karma points
    Aug 04, 2014 @ 04:47
    dan
    0

    Thank you. I tried that example before but didn't see how to apply it for the render macro statement. All I needed to do was move my statement inside the @{ }. I'm not familiar with this kind of syntax.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "umbLayout.cshtml";
    if(CurrentPage.HasValue("yourMediaPickerAlias")){  
    var dynamicMediaItem =Umbraco.Media(CurrentPage.yourMediaPickerAlias);

            @Umbraco.RenderMacro("InsertWidgit", new {mediaFile=@dynamicMediaItem.someFile, [email protected], [email protected]})
       } 
    }

     

Please Sign in or register to post replies

Write your reply to:

Draft