Any way to read the path of an image resource?

Say I have an image resource called $img. Is there any way I can read the path of the image, without using .RelPermalink(it pushes the image to public, which I’d like to avoid).

The use case is using it as a variant for partialCached. If there’s another unique way to refer to an image resource, please let me know.

$img.Name is not a valid choice because two images(Page resources) will have the same .Name value based on the path relative to the page.

E.g. content/foo/a.jpg → $img.Name = a.jpg
content/bar/a.jpg → $img.Name = a.jpg

I’d like to distinguish between the above two cases.

You can use $img.Key

1 Like

Thanks, I’ll test this and get back to you. By the way, is it there in the documentation somewhere? Because I couldn’t find anything like this even I searched earlier.

It’s in the GoDocs, so technically it’s in a documentation, but not on Gohugoio. It’s mostly meant for internal use, though, but once/if we get this done: New docs content structure · Issue #1 · gohugoio/gohugoioTheme2 · GitHub – then we should make sure that all the methods and functions are covered in the docs.


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