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
    Feb 14, 2022 @ 15:11
    Mike Manusama
    0

    Get the image picker image URL in a Macro

    What is the best way to get the URL to a media picker image in an Umbraco 9 macro? It seems like a pretty easy ask, but Umbraco docs are pretty frustrating to follow (as a designer who dabbles in coding). It seems like a pretty easy ask and I find that with each version of Umbraco they change up the way in which you do something this easy. Here is the code I am using with som eof my unssuccessful tries commented out (some of these worked in previous Umbraco versions)

        @inherits Umbraco.Cms.Web.Common.Macros.PartialViewMacroPage
        @using Umbraco.Extensions
    
    
    @{
        var testName = Model.MacroParameters["cdsTestimonialName"];
        var testTitle = Model.MacroParameters["cdsTestimonialTitle"];
        var test = Model.MacroParameters["cdsTestimonial"];
    
        var getTestPic = Model.MacroParameters["cdsTestimonialImg"].ToString();
        @* var fileimg = Umbraco.Media(getBioPic); *@
    
        @* var fileimg = Umbraco.TypedMedia(getBioPic); *@
    
        @* var fileImg = Umbraco.Media(getBioPic);
        var fileImgUrl = fileImg.Url; *@
    
    
    
    <div class="cds-card-bio">
        <div class="row g-5">
            <div class="col-3">
                <p>@getTestPic</p>
                <img src="/need/the/image-url.jpg" class="img-fluid rounded-circle cds-shadow" alt="@testName - @testTitle">
            </div>
            <div class="col-9">
                <h4 class="cds-m-0">@testName</h4>
                <h5 class="cds-subheader">@testTitle</h5>
                <p>@test</p>
            </div>
        </div>
    </div>
    
    }
    
  • Mike Manusama 45 posts 195 karma points
    Feb 15, 2022 @ 16:41
    Mike Manusama
    100

    For anyone wondering, I solved this using:

    var getTestPic = Umbraco.Media( Model.MacroParameters["cdsTestimonialImg"] );
    
  • Hon Guin Lee 5 posts 75 karma points
    Sep 23, 2022 @ 12:24
    Hon Guin Lee
    0

    Nice thanks so much, I tried everything else using UmbracoHelpers and Umbraco.Content() and didnt work, so it must be a new implementation.

  • 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