Copied to clipboard

Flag this post as spam?

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


  • Will Tran 3 posts 73 karma points
    Mar 07, 2019 @ 09:04
    Will Tran
    0

    Get image url from MacroPartialView Umbraco 8

    Hi I used to be able to get image url from macro with:

    <code.
    var imgMain = Model.MacroParameters["image"];
        int imgWidth = Convert.ToInt32(Model.MacroParameters["imageWidth"]);
        var mediaItemOne = Umbraco.TypedMedia(imgMain);
        <img src='@mediaItemOne.Url.GetCropUrl(width:imageWidth)' alt=''/ >
    </code>
    

    What is the new way in Umbraco 8 as I get the following error now and I cannot find any documentation on how to do it:

    UmbracoHelper' does not contain a definition for 'TypedMedia' and no accessible extension method 'TypedMedia' accepting a first argument of type 'UmbracoHelper' could be found (are you missing a using directive or an assembly reference?)

  • Marc Goodson 1451 posts 9716 karma points MVP 5x c-trib
    Mar 07, 2019 @ 09:31
    Marc Goodson
    2

    Hi Will

    Your code has not shown up in your post, but in V8 the previously sometimes confusingly named 'TypedContent' and 'TypedMedia' methods have been renamed, as there is now only one way (no dynamics) of retrieving objects via these methods you can now simply use

    IPublishedContent mediaItem = Umbraco.Media(id);
    

    where id is either a guid or string or integer id (depending on how your picker is setup)

    or you can pass an array of ids in to retrieve an IEnumerable

    eg

    IEnumerable<IPublishedContent> mediaItem = Umbraco.Media(arrayOfIds);
    

    regards

    Marc

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies