Skip to content

Commit

Permalink
Set image alt attribute to empty string if media text is null or empty (
Browse files Browse the repository at this point in the history
OrchardCMS#16859)

---------

Co-authored-by: Mike Alhayek <[email protected]>
  • Loading branch information
DrewBrasher and MikeAlhayek authored Oct 10, 2024
1 parent 28de8c7 commit d4e5e0d
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
var mediaTexts = Model.Field?.MediaTexts ?? Array.Empty<string>();
var name = (Model.PartFieldDefinition.PartDefinition.Name + "-" + Model.PartFieldDefinition.Name).HtmlClassify();
}
@if (paths.Any())
@if (paths.Length > 0)
{
<div class="field field-type-mediafield field-name-@name">
<span class="name">@Model.PartFieldDefinition.DisplayName()</span>
@for (int i = 0; i < paths.Length; i++)
{
var path = paths[i];
var url = Orchard.AssetUrl(path);
var text = !string.IsNullOrEmpty(mediaTexts.ElementAtOrDefault(i)) ? mediaTexts[i] : path;

if (Orchard.IsImageFile(path))
{
<img src="@url" alt="@text">
var alt = !string.IsNullOrEmpty(mediaTexts.ElementAtOrDefault(i)) ? mediaTexts[i] : string.Empty;
<img src="@url" alt="@alt" />
}
else
{
var text = !string.IsNullOrEmpty(mediaTexts.ElementAtOrDefault(i)) ? mediaTexts[i] : path;
<a href="@url">@text</a>
}
}
Expand Down

0 comments on commit d4e5e0d

Please sign in to comment.