Copied to clipboard

Flag this post as spam?

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


  • Edgar Rasquin 326 posts 925 karma points
    Jul 04, 2018 @ 09:09
    Edgar Rasquin
    0

    How to retrieve MediaType custom PropertyValue from within Grid Editor template

    Hi there,

    I wondered wether someone could point out how to access a custom PropertyValue of a MediaType (Image):

    enter image description here

    from within Grid Editor template:

    @model dynamic
    @using Umbraco.Web.Templates
    
    @if (Model.value != null)
    {   
        var url = Model.value.image;
        if(Model.editor.config != null && Model.editor.config.size != null){
            url += "?width=" + Model.editor.config.size.width;
            url += "&height=" + Model.editor.config.size.height;
    
        if(Model.value.focalPoint != null){
            url += "&center=" + Model.value.focalPoint.center +"," + Model.value.focalPoint.center;
            @*url += "&mode=crop";*@
        }
    }
    
    <!-- \Views\Partials\Grid\Editors\Media.cshtml -->
    <div style="overflow:hidden">
        <img src="@url" alt="@Model.value.caption">
    </div>
    if (Model.value.caption != null)
    {
        <p class="caption">@Model.value.caption</p>
    }
    

    }

  • Jason Elkin 38 posts 351 karma points MVP 2x c-trib
    Jul 04, 2018 @ 10:23
    Jason Elkin
    100

    The grid editor itself doesn't store the whole media item with all of its properties, but it does store its ID so you can use an Umbraco Helper to get the media item.

    First Replace @model dynamic with the following, then you can get the media item and its properties.

    @inherits UmbracoViewPage<dynamic>
    ...
    @{ 
        IPublishedContent yourMedia = Umbraco.TypedMedia((int)Model.value.id)
        int rotation = yourMedia.GetPropertyValue<int>("imageRotation");
    }
    
  • Edgar Rasquin 326 posts 925 karma points
    Jul 04, 2018 @ 10:44
    Edgar Rasquin
    0

    Hi Jason,

    thank you very much. Works perfekt!

    cheers

Please Sign in or register to post replies

Write your reply to:

Draft