Nested Resource path for Homepage (index.html) to query

Hi everyone,

It’s seems that homepage resources needs to be located alongside of _index.md in the root of /content directory. It doesn’t accept resources to be located in a nested directory like regular pages do. Is it possible to allow nested resources path for index.html template to query ?

In other words. I usually do something like this :

/content
    main.jpg
    _index.md
    /foo
        /bar
            index.md
            /static
                john.jpg
                doe.png

Where for each pages of foo section, there relative resources is located in a static directory.
Then simply :

  {{ $img := .Resources.GetMatch "static/john.jpg" }}
  <img src="{{ ($img.Resize "1200x q90").RelPermalink }}">

In homepage (/themes/"…"/layouts/index.html) if I do the following, everything is working fine:

  {{ $img := .Resources.GetMatch "main.jpg" }}
  <img src="{{ ($img.Resize "1200x q90").RelPermalink }}">

Now if I try to replicate the directory pattern at root like this, creating a “/static” dir at /content/static :

/content
    _index.md
    /static
        main.jpg
    /foo
        /bar
            index.md
            /static
                john.jpg
                doe.png

and doing this query in homepage (/themes/"…"/layouts/index.html) :

  {{ $img := .Resources.GetMatch "static/main.jpg" }}
  <img src="{{ ($img.Resize "1200x q90").RelPermalink }}">

I’ve got a nil pointer reference, no ressources are fetched. See error code :

execute of template failed: template: index.html:19:20: executing "index.html" at <$img.Resize>: nil pointer evaluating resource.Resource.Resize

If i’m in a regular page bundle, I can do the “static/asset.jpg|png|pdf…” query. But not on index.html.
Of course it isn’t a big deal. But if someone can confirm this behavior, maybe I’m missing something here.

Thank you. I wish you all a nice day.

Stack :
- Windows 64
- Hugo regular 0.55.6

1 Like

Hi,

From the docs on where resources for branch bundles (_index.md) live: https://gohugo.io/content-management/page-bundles/

Only in the directory level of the branch bundle directory i.e. the directory containing the _index.md

If you want to nest your resources for content/_index.md inside a subfolder, you could instead put them in a headless bundle: https://gohugo.io/content-management/page-bundles/#headless-bundle

1 Like

@pointyfar Sorry I missed that… Thank you for your time and answer ! That is exactly what I need.
Have a nice day.