Filter resources in subdirectories with Resources.Match


I’m trying to access the image “img-in-a.png” inside the subdirectory “a” (inside the content directory) with Resources.Match.

Using the homepage template (layouts/index.html) I expected this to work:

{{ $img := .Resources.Match "a/img-in-a.png" }}

But the result is empty.

{{ printf "%#v" $img }} prints resource.Resources(nil)

What am I doing wrong?

The project is available at:

PS: I’m using Resources.Match because I think it is the preferred method for a multilingual setup but I’m not there yet.

try {{ $img := .Resources.Match “**/img-in-a.png” }}

Thanks for your help. Unfortunately this doesn’t work either. Same result, i.e. empty result.

The project is now available at:

the home page is no page bundle - rename it to index.html

I’m confused. The documentation says the home page can be a branch bundle. According to the docs the name of the index file in branch bundles should be You were talking about renaming the index file “” in content to “index.html”, am I right? Could you elaborate on your answer? Thanks again for your help.

i checked your repo, no idea - sorry

No sweat, thanks anyway.

As per the repo /a/ is a regular page. To fetch its resource img-in-a.png on the homepage first you need to call the regular pages page group with something like range .Site.RegularPages and then within this context you can fetch the image resource more-or-less as mentioned above.

To limit the scope of the page group I would suggest that you filter it by a parameter or anything else that suits your project’s needs.

Thanks for your detailed answer! I learned that Resources.Match doesn’t include other content directories which relate to pages.

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