Copied to clipboard

Flag this post as spam?

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


  • Mike Manusama 45 posts 195 karma points
    Jul 24, 2018 @ 17:53
    Mike Manusama
    0

    Single media Picker for Macro

    I am on Umbraco v7.4 on one site and v7.10 on another.

    On v7.10, I created an image parameter in my Partial View that allows a user to add an image to a macro that brings in the image src. The code for that is below.

    @{
    var svcIconMain = Model.MacroParameters["ServiceIconFront"];
    var mediaItemOne = Umbraco.TypedMedia(svcIconMain);
    <img src='@mediaItemOne.GetPropertyValue("umbracoFile")' alt='' class="front-icon"/>}
    

    Conversely, when I add that same code to 7.4 nothing is output, rather I get an error. I will say, 7.10 I am using the "Content Picker" type for my Macro, while I am trying to use "Single Media Picker" for the 7.4 (They don't have content picker for 7.4). I cant seem to find a way to add an image into a Macro on 7.4 and I have found nothing in the forum/YouTube/Umbraco.tv . So I guess I will ask first, is this not an acceptable way to be using a Macro in the first place, or is the solution just simple enough where I am totally missing something? Thanks in advance!

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Jul 25, 2018 @ 00:06
    Marc Goodson
    100

    Hi Mike

    in your 7.4 site, what is the value of the svcIconMain variable? (just write that bit out) eg are you able to read a value from the ServiceIconFront macro parameter, when it is using the Single Media Picker type?

    If you are getting an Id here, then your picker is working, and Umbraco.TypedMedia should return the Media item related to that Id.

    Finally I'd change the way you write out the img src attribute to be

    @mediaItemOne.Url

    the umbracoFile property can either be the url of the image or it can be a JSON blob containing image crop information depending on how you have that property configured, but the .Url helper will always return the Url.

    regards

    Marc

  • Mike Manusama 45 posts 195 karma points
    Jul 27, 2018 @ 14:34
    Mike Manusama
    0

    that worked. Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft