Help writing layouts

I am trying to build a website for a small business that holds monthly auctions.
For the auctions I need 3 different layouts:

  • A list of upcoming and past auctions.
  • A list of lots in each auction.
  • Information about the individual lot.

The individual lot layout should be easy enough (as I can just use a single page template) but I am not sure how to write the templating to show the correct information and what the best way to structure the files should be.
Currently this is what my folder structure looks like:

├── content
│   └── auctions
│       ├── 2018-08-01
│       │   ├── 02.md
│       │   ├── 03.md
│       │   └── index.md
│       ├── 2018-09-01
│       │   ├── 01.md
│       │   ├── 02.md
│       │   ├── 03.md
│       │   └── index.md
│       ├── 2018-10-1
│       │   ├── 01.md
│       │   ├── 02.md
│       │   ├── 03.md
│       │   └── index.md
│       └── _index.md
└── layouts
    └── auctions
        ├── auction-catalogue.html
        ├── auctions.html
        └── single.html

I originally started looking around for other websites or themes to see how other people have solved this problem, but I couldn’t find anything else that was 3 sections deep (I’m sure there are plenty out there, I just didn’t haven’t found any yet.)
For the auctions.html layout (which is for the list of upcoming and past auctions) I added the following front-matter to the auctions/_index.md file:

type = "auction"
layout = "auctions"

Then in the auction/auctions.html layout I tried to range over all the pages in the auction section, but I couldn’t figure out a way to exclude items that use the single.html template, meaning I got a list of all the auctions, as well as all the lots. Instead I added layout = "lot" to the front-matter on each lot and created a corresponding layout (lot/single.html) which did the trick. Here is what my auctions/auctions.html layout looks like:

{{ define "main" }}
<main class="max-w-md p-5 mx-auto w-full">
  <h1>{{ .Title }}</h1>
  {{ .Content }}

  {{ if eq .Title "Auctions" }}
  <ul class="list-reset m-0">
    {{ range where .Site.Pages.ByDate.Reverse "Section" "auctions" }}
    {{ if ne .Kind "section" }}
    <li class="mb-5">
      <a href="{{ .Permalink }}" title="{{ .Title }}">{{ .Title }}</a>
      {{ .Content }}
    </li>
    {{ end }}
    {{ end }}
  </ul>
  {{ end }}

  <footer>
    {{ if eq .Paginator.HasPrev true }}
    <a href="{{ .Paginator.Prev.URL }}" title="Go to page {{ .Paginator.Prev.PageNumber }}">Previous page ({{ .Paginator.Prev.PageNumber }} / {{ .Paginator.TotalPages }})</a>
    {{ end }}

    {{ if eq .Paginator.HasNext true }}
    <a href="{{ .Paginator.Next.URL }}" title="Go to page {{ .Paginator.Next.PageNumber }}">Next page ({{ .Paginator.Next.PageNumber }} / {{ .Paginator.TotalPages }})</a>
    {{ end }}
  </footer>
</main>
{{ end }}

Unfortunately I couldn’t get the auction-catalogue.html layout to show the lots (I think it might be a scope issue as they were now in a different section? I also couldn’t find a good way to show the children of a section.
I also tried building the site, and it looks like the lots don’t even get built, I’m not sure why. I’ve given each lot the following front-matter:

type = "lot"
layout = "single"

I feel like I’m at a bit of a dead-end here, so I’d really appreciate some help.
I’ve put the code up on GitHub and it’s also live on Netlify if anyone would like to take a look (or even better, submit a pull request for me.)

Thanks for reading.

—Luke

can the .Page properties help?

.IsPage for single pages
.IsNode for Lists etc

If your .md is under /content/auction the type is “auction” per default

Hope this helps

In addition to what @ju52 mentioned, to add logic to your template to check if the pages are of type auction:

{{ if eq .Type "auction” }}
...
{{ end }}