Add article title as alt text to resrouce image

I’m picking up a resource that is scoped to “featured” images:

{{ with .Resources }}
    {{ with .GetMatch "{featured*}" }}
	{{ $featured := .Fill "720x450" }}
		{{ with $featured }}
			<div class="article-thumbnail-wrapper">
				<img src="{{ .Permalink }}" alt="{{ $.Title }}" class="article-thumbnail">
			</div>
		{{ end }}
	{{ end }}
{{ end }}

As you can see, the alt text is currently a site param (getting the title of my site). I’d love to be able to use the Title of the article that it is associated with.

I’ve tried adding .Params.Title — which grabes the image name.

I’m not sure what else to try. Any ideas welcome! Thank you :pray:

1 Like

$.Page.Title is what you want to use. Inside of any range or with the dot is what is inside of the range or with, not the “global” context. Common issue :wink:

1 Like

I’d strongly suggest setting an additional parameter for image alt text. Unless the image is an image of the title of the page then setting the title as the alt text is almost certainly incorrect. Generally, alt text should describe the content of the image.

This decision tree might help: An alt Decision Tree • Images • WAI Web Accessibility Tutorials

3 Likes

Thanks! The tree was helpful!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.