Range over content w/ latest treated different

I have two areas in html that I want to look different but pull from the same content.
I want area one to just pull the latest .md from a section, and area two to pull all the rest of the .md files.

Edit: this almost works - except the value of the $index is the path to the .md, not an integer.

  {{ range $index, where .Pages.ByDate "Section" "my-section" }}
  {{ if eq $index 1 }}
  ...code
  {{ else }}
  ..code
  {{ end }}
  {{ end }}

Edit: this does work with two ranges. Is it better practice to have one?

{{ range first 1 (where .Pages "Section" "my-section") }}
...
{{ end }}
{{ range after 1 (where .Pages "Section" "my-section") }}
...
{{ end }}

Hi,
That’s because this is not the correct syntax for accessing the array element and index from a range. See this example: Introduction to Hugo Templating | Hugo

It’s really up to you :smiley:
(as a personal preference I would probably do it like your first set up, with a range and if-else inside)

1 Like