Copied to clipboard

Flag this post as spam?

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


  • Ben Hill 26 posts 126 karma points
    Jun 29, 2021 @ 13:13
    Ben Hill
    0

    How to add a custom image property to this code - Umbraco 7

    Hi All

    We are attempting to add an alt tag to all of our on-site imagery.

    To help with that we have added a custom property to the Image media type called altText, I have managed to render this new property in the code for 3 types of components thanks to some help from this forum and in particular Marc at uSkinned, but I am trying to add this to the "Grid" component which I have added the relevant code for below.

    @if (Model.value != null)
    {   
        var url = Model.value.image;
        if(Model.editor.config != null && Model.editor.config.size != null){
            url += "?width=" + Model.editor.config.size.width;
            url += "&height=" + Model.editor.config.size.height;
    
            if(Model.value.focalPoint != null){
                url += "&center=" + Model.value.focalPoint.top +"," + Model.value.focalPoint.left;
                url += "&mode=crop";
            }
        }
    
        var altText = Model.value.altText ?? Model.value.caption ?? string.Empty;
    
        <img src="@url" alt="@altText">
    
        if (Model.value.caption != null)
        {
            <p class="caption">@Model.value.caption</p>
        }
    }
    

    If anyone has any ideas how to add the new property to the altText variable in the above I would really appreciate a pointer.

    Thanks everyone

Please Sign in or register to post replies

Write your reply to:

Draft