How to get resources inside folder from single page within a branch bundle

I have a branch bundle like this:

content/mailbox/
- _index.md
- mails/
 - mail.md
- images/
  - image.jpg

In mail.md, I add img: image.jpg in front matter. In the template file of mail.md, I try to get this image using:

{{ with (printf "images/%s" .Params.img | .Resources.GetMatch) }}

or

{{ with (printf "images/%s" .Params.img | .Parent.Resources.GetMatch) }}

but neither of them work. I also try move the images folder into mails folder, still not work.

The only way is move the image.jpg out of images like this:

content/mailbox/
- _index.md
- image.jpg
- mails/
 - mail.md

then I can get the image with .Parent.Resources.GetMatch.

Is there any way I can get the image while keeping it inside folder?

You have a branch bundle

so the answer is no.

Here’s a solution inspired by Different ways to get an image as page resource in Hugo

I add a _index.md in image folder to make it a section

content/mailbox/
- _index.md
- mails/
 - mail.md
- images/
  - _index.md
  - image.jpg

then I can get the image with:

{{ range where .Site.Pages ".Section" "mailbox" }}
    {{ with .Page.Resources.GetMatch "image.jpg" }}
        <img src="{{ .RelPermalink }}">
    {{ end }}
{{ end }}

Sorry I miss that :sweat_smile:. But I find a solution, so now the answer is yes.

1 Like

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