Copied to clipboard

Flag this post as spam?

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


  • Dibs 202 posts 991 karma points
    Jun 25, 2015 @ 07:42
    Dibs
    0

    Model.MacroParameters["ImagesToRender"]

    Dear Umbraco Forum Team

    How do I render media image from macro parameters in a view using strongly typed Model.Macroparameters["ImagesToRender"]

    Thanks Dibs

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 25, 2015 @ 08:01
    Dennis Aaen
    100

    Hi Dibs,

    With this code below you should get what you are after.

        @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    
        @*    
            How it works:
                - Confirm the macro parameter has been passed in with a value
                - Display any individual image
    
            Macro Parameters To Create, for this macro to work:
            Alias:mediaId     Name:Select folder with images    Type:Single Media Picker
        *@
    
        @{ var mediaId = Model.MacroParameters["mediaId"]; }
        @if (mediaId != null)
        {
            @* Get the media item associated with the id passed in *@
            var media = Umbraco.TypedMedia(mediaId);
            <img src="@media.GetPropertyValue("umbracoFile")" alt="@media.GetPropertyValue("Name")" />
    
     }
    

    Remember to add the parameter to the marco, and the important thing here is the alias of the parameter.

    Hope this helps,

    /Dennis

  • Dibs 202 posts 991 karma points
    Jun 25, 2015 @ 09:38
    Dibs
    1

    Cheers Dennis

    works a treat

    Dibs

Please Sign in or register to post replies

Write your reply to:

Draft