Copied to clipboard

Flag this post as spam?

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


  • David 29 posts 200 karma points
    Feb 21, 2019 @ 14:19
    David
    0

    Global image alternative text

    Is there a way to achieve global alternative text for all images on a site?

    I have created a new property under the Image media type, and i got this working for my blog posts only.

    @{
    
    IPublishedContent mainImage = Umbraco.AssignedContentItem.GetPropertyValue<IPublishedContent>("articleImage");
    string mainImageAltText = mainImage.GetPropertyValue<string>("umbracoAltText"); }
    

    Is there a way I can achieve this for every image across my site? Like if i put my markup in the master or a controller? Sorry new to Umbraco/MVC here so any guidance would be much appreciated.

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Feb 21, 2019 @ 22:39
    Alex Skrypnyk
    0

    Hi David

    The good way of doing it - create a helper that returns image URL an alternative text or even full tag for you. Then use this helper everywhere on the site.

    Thanks,

    Alex

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Feb 25, 2019 @ 16:15
    Alex Skrypnyk
    0

    Hi David

    Did you find a solution for this topic? Can you share with our community?

    Alex

  • David 29 posts 200 karma points
    Feb 28, 2019 @ 15:21
    David
    0

    No luck on this yet. Would I put this helper within my master? How would I then write it to check all images per page? All I can find when searching the forums is if I were to select each property individually.

  • Allan 42 posts 192 karma points
    Feb 28, 2019 @ 17:37
    Allan
    0

    Hi David,

    You could use a dictionary item and then make all logic fall back to that dictionary value...

    So, if an 'alt' value exists (from a page field value maybe or simply Model.Name) then use it otherwise use the dictionary item.

    But obviously Alex's method is also a workable solution.

Please Sign in or register to post replies

Write your reply to:

Draft