Copied to clipboard

Flag this post as spam?

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


  • John Churchley 272 posts 1257 karma points c-trib
    Feb 06, 2015 @ 12:14
    John Churchley
    0

    Options for Alt attribute with Image Cropper

    Hi, 

    I was wondering how people have handled the absense of an alt field in the image cropper? 

    Currenlty I have a additional text string field for Alt but this doesn't seem right.

    Cheers

    John

  • Barry Fogarty 493 posts 1129 karma points
    Feb 06, 2015 @ 14:08
    Barry Fogarty
    100

    Hi John,

    Adding an 'altText' field to the image media type is the usual way.  You can also add a fallback to the media node name in your code, e.g. an extension method like image.AltText().   NB This would use the same alt text for all crops - I'm not sure how you would go about having different values for different crops, if thats what you are after.  But it would be a lot more difficult, probably you would need to a customised mage cropper property editor.

     

    public static string AltText(this IPublishedContent content)

            {

                return content.GetPropertyValue<string>("altText").HasValue() ? content.GetPropertyValue<string>("altText") : content.Name;

            }

    NB HasValue() above is also a simple extension method:

    public static bool HasValue(this object input)

            {

                return input != null && !string.IsNullOrWhiteSpace(input.ToString());

            }

     

  • 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