Key
Syntax
RESOURCE.Key
Returns
string
By way of example, consider this site configuration:
hugo.
baseURL: https://example.org/docs/
baseURL = 'https://example.org/docs/'
{
"baseURL": "https://example.org/docs/"
}
And this template:
{{ with resources.Get "images/a.jpg" }}
{{ with resources.Copy "foo/bar/b.jpg" . }}
{{ .Key }} → foo/bar/b.jpg
{{ .Name }} → images/a.jpg
{{ .Title }} → images/a.jpg
{{ .RelPermalink }} → /docs/foo/bar/b.jpg
{{ end }}
{{ end }}
We used the resources.Copy
function to change the publishing path. The Key
method returns the updated path, but note that it is different than the value returned by RelPermalink
. The RelPermalink
value includes the subdirectory segment of the baseURL
in the site configuration.
The Key
method is useful if you need to get the resource’s publishing path without publishing the resource. Unlike the Permalink
, RelPermalink
, or Publish
methods, calling Key
will not publish the resource.