# .Page.Resources directory from a \_index.md shortcode

**URL:** <https://discourse.gohugo.io/t/page-resources-directory-from-a-index-md-shortcode/30797>\
**Category:** support\
**Created:** [January 22, 2021, 2:27pm UTC](https://discourse.gohugo.io/t/page-resources-directory-from-a-index-md-shortcode/30797 "2021-01-22T14:27:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joeborg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/joeborg/32/12657_2.png) [@joeborg](https://discourse.gohugo.io/u/joeborg)\
**Post date:** [January 22, 2021, 2:27pm UTC](https://discourse.gohugo.io/t/page-resources-directory-from-a-index-md-shortcode/30797/1 "2021-01-22T14:27:17Z")

</div>

> Page resources are available for [page bundles](https://gohugo.io/content-management/page-bundles/) only, i.e. a directory with either a `index.md` , or `_index.md` file at its root. Resources are only attached to the lowest page they are bundled with, and simple which names does not contain `index.md` are not attached any resource.

the above documentation indicates that I can bundle a bunch of image files in a directory at the same level as an `_index.md` or `index.md` file and access it through a shortcode. It works with index.md files but I cannot access the images unless they are spilled into the same directory as the `_index.md` file.

It would be nice to avoid having an exception for ‘list’ pages. I also have a fetish for wrapping everything in directories for better management by absent minded maintainers.

Any pointers appreciated.

Sample shortcode:

```auto
{{ $_path := ( .Get "path" ) | default "gallery/pic*.jpg" }}

{{ warnf "Checking %q for pictures..." $.Page.File.Path }}

{{ with .Page.Resources.Match $_path }}
  {{ warnf "Located picture gallery at %q" $_path }}
  {{ partial "collections/gallery/c" . }}
{{ else }}
  {{ warnf "Failed to get picture gallery at %q" $_path }}
{{ end }}

{{ with .Inner }}
  {{ . | markdownify }}
{{ end }}

```

compilation output:

```auto
Start building sites … 
WARN 2021/01/22 15:50:25 Checking "about/lead/index.md" for pictures...
WARN 2021/01/22 15:50:25 Located picture gallery at "gallery/pic*.jpg"
WARN 2021/01/22 15:50:25 Checking "services/_index.md" for pictures...
WARN 2021/01/22 15:50:25 Located picture gallery at "pic*.jpg"
WARN 2021/01/22 15:50:28 Checking "about/_index.md" for pictures...
WARN 2021/01/22 15:50:28 Failed to get picture gallery at "gallery/pic*.jpg"

```

content tree:

```auto
$ tree
.
|-- _index.md
|-- about
| |-- _assets
| | `-- pic.jpg
| |-- _index.md
| |-- affiliations
| | `-- index.md
| |-- pic.jpg
| |-- gallery
| | |-- pic1.jpg
| | |-- pic2.jpg
| | |-- pic3.jpg
| | |-- pic4.jpg
| | `-- pic5.jpg
| |-- lead
| | |-- gallery
| | | |-- pic1.jpg
| | | |-- pic2.jpg
| | | |-- pic3.jpg
| | | |-- pic4.jpg
| | | `-- pic5.jpg
| | `-- index.md
| `-- follow
| `-- index.md
|-- contact-us
| `-- index.md
|-- impressum
| |-- _index.md
| |-- copyright
| | `-- index.md
| |-- legal
| | `-- index.md
| |-- privacy
| | `-- index.md
| `-- sitemap
| `-- index.md
`-- services
    |-- _index.md
    |-- commercial
    | |-- chaplin.jpg
    | `-- index.md
    |-- corporate
    | |-- chaplin.jpg
    | `-- index.md
    |-- gallery
    |-- moarr
    | |-- pic.jpg
    | `-- index.md
    |-- pic1.jpg
    |-- pic2.jpg
    |-- pic3.jpg
    |-- pic4.jpg
    |-- pic5.jpg
    `-- lesss
        |-- pic.jpg
        `-- index.md

```

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [January 22, 2021, 3:04pm UTC](https://discourse.gohugo.io/t/page-resources-directory-from-a-index-md-shortcode/30797/2 "2021-01-22T15:04:54Z")

</div>

In short: No. you can’t access page bundle ressources from outside the page bundle. Depending on what you really are trying to achieve (I am not sure I get it fully) you have three options:

1. rethink your content structure. I could think of a `index.md` (no `_index.md`) in a folder along other `title1.md` and so on files. Those files all could then access their “local” page bundle resources. I did not test this, but am pretty sure it works.

2. You should be able to retrieve images from the `assets` folder via `{{ $image := resources.Get "images/imagename.jpg" }}` and then process them as you would in a page bundle. Put all galleries into the assets folder? Might be an option?

3. There is always .GetPage. With this you could for instance put an index.md inside of the gallery page bundles and access them via `{{ $page := .GetPage “about/gallery” }}

> **[.GetPage](https://gohugo.io/functions/getpage/#readout)**
>
> Gets a \`Page\` of a given \`path\`.

---

<div class="post-metadata">

**Author:** ![joeborg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/joeborg/32/12657_2.png) [@joeborg](https://discourse.gohugo.io/u/joeborg)\
**Post date:** [January 22, 2021, 3:22pm UTC](https://discourse.gohugo.io/t/page-resources-directory-from-a-index-md-shortcode/30797/3 "2021-01-22T15:22:24Z")

</div>

the documentation states that `_index.md` and `index.md` directories are the same in this regard:

> A Page Bundle can be one of:
> 
> Leaf Bundle (leaf means it has no children)  
> Branch Bundle (home page, section, taxonomy terms, taxonomy list)

Yet I cannot access a top level asset directory in the branch bundle but I can access an asset directory in a leaf bundle. The shortcode can read the picture gallery in `about/lead/index.md` but not in `about/index.md`, where it returns `null`:

```auto
|-- about
| |-- _assets
| | `-- pic.jpg
| |-- _index.md
| |-- affiliations
| | `-- index.md
| |-- pic.jpg
| |-- gallery
| | |-- pic1.jpg
| | |-- pic2.jpg
| | |-- pic3.jpg
| | |-- pic4.jpg
| | `-- pic5.jpg
| |-- lead
| | |-- gallery
| | | |-- pic1.jpg
| | | |-- pic2.jpg
| | | |-- pic3.jpg
| | | |-- pic4.jpg
| | | `-- pic5.jpg
| | `-- index.md

```

further down in the documentation:

```auto
leaf bundle: Where can the Resources live? At any directory level within the directory.
branch bundle: Only in the directory level **of** directory i.e. the directory containing the `_index.md` ([ref](https://discourse.gohugo.io/t/question-about-content-folder-structure/11822/4?u=kaushalmodi)).

```

seems implied that directories without an `index.md` are still considered a leaf bundle here. I thought bundles required the directory to contain an `index.md` or \_index.md`. A confirmation would be nice.

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [January 22, 2021, 3:30pm UTC](https://discourse.gohugo.io/t/page-resources-directory-from-a-index-md-shortcode/30797/4 "2021-01-22T15:30:26Z")

</div>

That might be phrased wrong or unclear. A directory with `_index.md` is not a page bundle but a section or subsection. Look at the table here: [Page Bundles | Hugo](https://gohugo.io/content-management/page-bundles/)

(I am not sure, why I have the term “page bundle” in my head, but it clearly is named “leaf bundle” in the docs. If a directory has an index.md it has no subfolders with \_index.md and everything inside this directory is available as “leaf bundle”.)

Did you try idea 3? That seems to me the closest to get the functionality you are seeking.

---

<div class="post-metadata">

**Author:** ![joeborg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/joeborg/32/12657_2.png) [@joeborg](https://discourse.gohugo.io/u/joeborg)\
**Post date:** [January 22, 2021, 3:32pm UTC](https://discourse.gohugo.io/t/page-resources-directory-from-a-index-md-shortcode/30797/5 "2021-01-22T15:32:34Z")

</div>

I’ll go for that workaround then. Thanks for your time.

---

<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:** [January 24, 2021, 3:32pm UTC](https://discourse.gohugo.io/t/page-resources-directory-from-a-index-md-shortcode/30797/6 "2021-01-24T15:32:35Z")

</div>

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