Do page resources work on /content/_index.md

Can /content/_index.md contain resources?

I ask because I have multiple page bundles that are working fine with resources. I have /content/window-cleaning-services/images, and /content/window-cleaning-services/index.md that defines the resources in the frontmatter along with additional params such as alt tags etc. All that works fine, I can query the resources etc.

But when I try to do the same from /content/_index.md non of the images load.

Here I have a shortcode called JobGallery. When used it loads all .png images from any directory in t he bundle that contains the word jobs. In my case, for this project, such directories will only be used to display images of my clients work:

<section class="gallery">
    <div class="container">
    <h2 class="heading-2">{{ .Get "title" }}</h2>
    <p class="lead-2">{{ .Get "description" }}</p>
    {{ with .Page.Resources.Match "*jobs*/*.png" }}
    <ul class="row">
        {{ range . }}
        <li class="col-12 col-md-4 col-lg-3 gallery-item">
            <a class="lightbox" href="{{ .Permalink }}">
               <img src="{{ .Permalink }}" width="100%" title="{{ .Title }}" alt="{{ .Params.alt }}">
            </a>
       </li>
       {{ end }}
    </ul>
   {{ end }}
  </div>
</section>

In my /content/_index.md I define resources like so. Defining resources like this is an absolute pain but as I require extra data for the images I can’t see any other way to do this:

++++
[[resources]]
src="recent-jobs-in-birmingham/large-window-cleaning.png"
title="Title here"
    [resources.params]
    alt="Alt here"
....
+++
{{< JobGallery
    title="Our Recent Work"
    description="A description for lead text"
>}}

I have the images for the index page stored in /content/recent-jobs-in-birmingham/.

This doesn’t work on the _index.md page but works everywhere else on the site.

Hi,

As per the docs on page bundles, allowed resources for branch bundles, ie those with _index.md can live

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

Is it possible to create a page bundle for the homepage?

If you mean a leaf bundle, I don’t think so. Making the content/index.md a leaf bundle means you can’t nest other pages under it.

You could create a headless bundle, .GetPage that, and put the resources meant for the homepage in there. There should be an example of headless bundles in the docs page I linked to above.

2 Likes

I think the headless bundle could work for my usecase. Testing now.

Solved it with your help :slight_smile:

<section class="gallery">
    <div class="container">
        <h2 class="heading-2">{{ .Get "title" }}</h2>
        <p class="lead-2">{{ .Get "description" }}</p>

        {{ $resources := cond .Page.IsHome (.Site.GetPage "recent-jobs-in-birmingham").Resources (.Page.Resources.Match "*jobs*/*.png") }}
        {{ with $resources }}
        <ul class="row">
            {{ range . }}
            <li class="col-12 col-md-4 col-lg-3 gallery-item">
                <a class="lightbox" href="{{ .Permalink }}">
                    <img src="{{ .Permalink }}" width="100%" title="{{ .Title }}" alt="{{ .Params.alt }}">
                </a>
            </li>
           {{ end }}
       </ul>
      {{ end }}
    </div>
</section>
2 Likes