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)
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
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());
}
is working on a reply...