Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for img tag helper not outputting alt attribute when specified #59

Merged
merged 4 commits into from
May 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Our.Umbraco.TagHelpers/ImgTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,15 @@ 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));
}
#endregion
else
{
output.Attributes.Add("alt", ImgAlt);
}
#endregion
}
else if (!string.IsNullOrEmpty(FileSource))
Expand All @@ -196,11 +199,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