You need to use a shortcode. There are posts in this forum about shortcodes that fetch image resources in Page Bundles. Shortcodes can be used in HTML content files.
Error: Error building site: "/bulk/tmp/quickstart/content/pictures/index.html:11:1": failed to render shortcode "image": failed to process shortcode: "/bulk/tmp/quickstart/themes/september/layouts/shortcodes/image.html:5:15": execute of template failed: template: shortcodes/image.html:5:15: executing "shortcodes/image.html" at <$img.Resize>: nil pointer evaluating resource.Resource.Resize
Thanks for the explanation. The problem is, indeed, related to the project origanisation.
First, my misconception was to consider resources as a series of key/value pairs. Hugo treats resources as resources, which means that the result of Resource.GetMatch will be null if the resource file cannot actually be found. Makes sense.
Then I was thinking in terms of web sites. Given these files:
I expect foo.png to be next to the index.html (it is, it works). Likewise I’d expect bar.png in ../images/bar.png – it is not… it would be served under that name but the actual file is in ../static/images/bar.png. I haven’t figured out how to solve this.
I personally avoid symlinks like the plague but I suppose you could use one for your use case.
OR
You could try setting the assetDir to /static/ and fetch bar.png with the method resources.Get. This method is quite useful when one needs to fetch a resource outside a Page Bundle, the catch is that it needs to reside in the assetDir.
The way I would do it would be to store the call to the image
e.g. {{ $img := resources.Get "PATH-to-asset" }}
and then render the associated meta data from the front matter of the page in which the image should be rendered like so:
{{ with $img }}
Title: {{ $.Page.Params.imgTitle }}
{{ end }}
OR
Within the assetDir place the image within a directory and add the metadata in an .md file right next to it and fetch its content with resources.Get again.
The front matter you quoted above belongs in the resources table that is meant for Page Resources. assets/images/bar.png is NOT a Page Resource.
It is an asset fetched on demand for use in the Page.
Therefore to render its metadata you would need to enter it in a front matter parameter outside the resources table. Like so:
imgTitle: Bar is barred
And then in the template (shortcode or whatever)
{{ $img := resources.Get "images/bar.png" }}
{{ with $img }}
<img src="$img.Permalink" alt="$.Page.Params.imgTitle">
{{ end }}
Or use whatever naming convention or Permalink variation suits your project.
But you should get the general idea from the above.
Notes
The $ dollar sign and the .Page variable will fetch the front matter parameter from within the context of the $img. This is how one accesses Page parameters from the lower level of a shortcode.
Likewise if imgTitle was entered in the .Params table of the project config it would be accessed with $.Site.Params.imgTitle.
Bottom line: Page resources are page resources only. They must reside next to or below the page itself. No reaching up, even though no error is given when a resource has src: ../images/foo.png.
Final question (for today ) Given the setup from post #8, when I use resource res1 (which is foo.png) and I use .RelPermalink I would expect foo.png in the generated HTML. However it is generated as /pictures/foo.png. With relativeURLs set in the config it becomes ../pictures/foo.png. Is that intentional?