Hi,
with this code I grab an image from a page bundle.
I link a resource from frontmatter.
{{ $img := (.Resources.ByType "image").GetMatch "featured-image" }}
{{ with $img }}
{{ partial "tools/img" (dict "img" . "alt" $img.Title ) }}
{{ end }}
Frontmatter
resources:
- name: featured-image
src: ImageName.jpg
I’m trying to cut the image file extension from: ImageName.jpg to ImageName to put it in the “alt” tag. Which approach do you recommend? Any advice?
bep
2
You could try
{{ $imageName := “foo.jpg” }}
{{ $imageName = $imageName | strings.TrimSuffix (path.Ext $imageName )}}
Or something…
Thanks @bep it works!
For clarity, I report the complete code:
{{ $img := (.Resources.ByType "image").GetMatch "featured-image" }}
{{ with $img }}
{{ $imageName := $img.Title }}
{{ $imageName = $imageName | strings.TrimSuffix (path.Ext $imageName )}}
{{ partial "tools/img" (dict "img" . "alt" $imageName ) }}
{{ end }}
1 Like
system
Closed
4
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.