Copied to clipboard

Flag this post as spam?

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


  • Søren Kottal 500 posts 3318 karma points MVP 2x c-trib
    Oct 30, 2014 @ 09:56
    Søren Kottal
    0

    Using Umbraco.Media in grid editor views (slimsy)

    How can I use Umbraco.Media for getting ie. ImageGetResponsiveUrl in the standard media.cshtml View in the new grid editor?

     

    I get an error, if I just paste the code from http://our.umbraco.org/projects/website-utilities/slimsy.

     

    This is probably simple for someone into Razor/C# :)

     

    media.cshtml is looking like this:

     

    @model dynamic
    @using Umbraco.Web.Templates
    @if (Model.value != null)
    {
    <div class="thumbnail">
            <img src="http://mce_host/forum/templating/templates-and-document-types/@Model.value.image" alt="@Model.value.caption" />
        </div>
    if (Model.value.caption != null)
        {
    <p class="caption">@Model.value.caption</p>
    }
    }
    

     

     

  • Jeavon Leopold 3005 posts 13196 karma points MVP 7x admin c-trib
    Oct 30, 2014 @ 10:45
    Jeavon Leopold
    102

    At the moment I would do this (I think Grid needs a strongly typed model, but that's not available yet):

    @inherits UmbracoViewPage<dynamic>
    @{    
        int nodeId;
        var res = int.TryParse(Model.value.id.ToString(), out nodeId);
    }
    @if (res && Model.value != null)
    {
        var typedMedia = Umbraco.TypedMedia(nodeId);
    
        <div class="thumbnail">
            <img src="@typedMedia.GetCropUrl()" alt="@Model.value.caption">
        </div>
        if (Model.value.caption != null)
        {
            <p class="caption">@Model.value.caption</p>
        }
    }
    
  • Hussein Khraibani 9 posts 80 karma points
    Mar 11, 2019 @ 12:29
    Hussein Khraibani
    0

    How would you do it in slimsy version 2?

    Thanks Jeavon

  • Søren Kottal 500 posts 3318 karma points MVP 2x c-trib
    Oct 30, 2014 @ 11:25
    Søren Kottal
    0

    Great!

     

    Thanks, Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft