# Filter resources in subdirectories with Resources.Match

**URL:** <https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355>\
**Category:** support\
**Created:** [May 8, 2020, 8:43am UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355 "2020-05-08T08:43:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![b12r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/b12r/32/11315_2.png) [@b12r](https://discourse.gohugo.io/u/b12r)\
**Post date:** [May 8, 2020, 8:43am UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355/1 "2020-05-08T08:43:47Z")

</div>

![hugo](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/2X/6/64fd81826344297342619e186983d29f866511b2.png)

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: [https://github.com/b12r/hugo-resources-match](https://github.com/b12r/hugo-resources-match)

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

---

<div class="post-metadata">

**Author:** ![ju52](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ju52/32/6749_2.png) [@ju52](https://discourse.gohugo.io/u/ju52)\
**Post date:** [May 8, 2020, 9:21am UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355/2 "2020-05-08T09:21:47Z")

</div>

> **[Page Resources](https://gohugo.io/content-management/page-resources/#pattern-matching)**
>
> Page Resources -- images, other pages, documents etc. -- have page-relative URLs and their own metadata.

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

---

<div class="post-metadata">

**Author:** ![b12r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/b12r/32/11315_2.png) [@b12r](https://discourse.gohugo.io/u/b12r)\
**Post date:** [May 8, 2020, 10:24am UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355/3 "2020-05-08T10:24:08Z")

</div>

> [@ju52](#):
>
> {{ $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: [https://github.com/b12r/hugo-resources-match](https://github.com/b12r/hugo-resources-match)

---

<div class="post-metadata">

**Author:** ![ju52](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ju52/32/6749_2.png) [@ju52](https://discourse.gohugo.io/u/ju52)\
**Post date:** [May 8, 2020, 1:38pm UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355/4 "2020-05-08T13:38:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![b12r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/b12r/32/11315_2.png) [@b12r](https://discourse.gohugo.io/u/b12r)\
**Post date:** [May 8, 2020, 2:42pm UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355/6 "2020-05-08T14:42:40Z")

</div>

I’m confused. The [documentation](https://gohugo.io/content-management/page-bundles/) says the home page can be a branch bundle. According to the docs the name of the index file in branch bundles should be \_index.md. You were talking about renaming the index file “\_index.md” in content to “index.html”, am I right? Could you elaborate on your answer? Thanks again for your help.

---

<div class="post-metadata">

**Author:** ![ju52](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ju52/32/6749_2.png) [@ju52](https://discourse.gohugo.io/u/ju52)\
**Post date:** [May 8, 2020, 4:02pm UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355/7 "2020-05-08T16:02:43Z")

</div>

i checked your repo, no idea - sorry

---

<div class="post-metadata">

**Author:** ![b12r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/b12r/32/11315_2.png) [@b12r](https://discourse.gohugo.io/u/b12r)\
**Post date:** [May 8, 2020, 6:17pm UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355/8 "2020-05-08T18:17:17Z")

</div>

No sweat, thanks anyway.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [May 8, 2020, 6:59pm UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355/9 "2020-05-08T18:59:02Z")

</div>

As per the repo `/a/index.md` 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](https://gohugo.io/functions/where/#readout) it by a parameter or anything else that suits your project’s needs.

---

<div class="post-metadata">

**Author:** ![b12r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/b12r/32/11315_2.png) [@b12r](https://discourse.gohugo.io/u/b12r)\
**Post date:** [May 8, 2020, 7:47pm UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355/10 "2020-05-08T19:47:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [May 10, 2020, 7:47pm UTC](https://discourse.gohugo.io/t/filter-resources-in-subdirectories-with-resources-match/25355/11 "2020-05-10T19:47:13Z")

</div>

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