Using index/key with pages

I have a set of pages under content like so:

├── content
│   ├── _index.md
│   └── art
│       ├── Dog
│       │   ├── Dog.png
│       │   ├── index.md
│       ├── Cat
│       │   ├── Cat.jpg
│       │   ├── index.md
│ 

In the home page I wish to pull out one page.
I can say:

{{ $pages := .Pages  }}
      {{ with index $pages 1 }}

I would like to get the page by name. Like maybe…

`      {{ with .GetPage "art/Dog/index.md" }}` 
or
`   {{ with index $pages "Dog" }} `

The first compiles but fails silently, the second does not compile.  How is this done?

Try:

{{ with (.GetPage "art/Dog") }}

Which can be called directly from your homepage template. No need to use a range.

Yes, that works. I see now, I was getting the “Path” wrong.

In the general case how do I interpret Path? I see this is the same as the URL when my browser is pointing at the page. But I am a bit lost as to how “Path” is defined in Hugo.

In this particular case, it’s helpful to think of the path as Sections + .File.ContentBaseName

For example, both of these pages would have a .File.ContentBaseName of Dog

art/Dog.md
art/Dog/index.md
1 Like