Skip to content

Commit

Permalink
Merge branch 'richarth-img-helper-alt-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
Warren Buckley committed May 5, 2023
2 parents a066876 + 6024561 commit c588003
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Our.Umbraco.TagHelpers/ImgTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,17 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
height = (originalHeight / originalWidth) * width;
}

#region Autogenerate alt text
#region Autogenerate alt text if unspecfied
if (string.IsNullOrWhiteSpace(ImgAlt))
{
output.Attributes.Add("alt", GetImageAltText(MediaItem));
}
else
{
output.Attributes.Add("alt", ImgAlt);
}
#endregion

#endregion
}
else if (!string.IsNullOrEmpty(FileSource))
Expand All @@ -196,11 +201,15 @@ public override void Process(TagHelperContext context, TagHelperOutput output)

imgSrc = AddQueryToUrl(FileSource, "width", width.ToString());

#region Autogenerate alt text
#region Autogenerate alt text if unspecfied
if (string.IsNullOrWhiteSpace(ImgAlt))
{
output.Attributes.Add("alt", GetImageAltText(FileSource));
}
else
{
output.Attributes.Add("alt", ImgAlt);
}
#endregion

#region If width & height are not defined then return a basic <img> with just a src, alt & class (if provided)
Expand Down

0 comments on commit c588003

Please sign in to comment.