Conditionally range over release notes by version

Hi, I have a long page of release notes on my website that I’m grouping by a minorVersion field in the front matter, currently. The problem is that I need to add a header at some point to denote the release notes that are for versions of the software that are no longer available.

What I’d like to do is:

  1. Have one section of my layout that ranges through and groups the release notes and conditionally renders any note with a minorVersion of >= 18.

  2. I’d then like a second section below that one that similarly ranges through the rest of the notes and then conditionally renders them in this second section if the minorVersion number is <=17.

How would I do this? I’ve tried nesting where statements to no avail, and I’ve tried to add the notes for the unavailable versions to a subdirectory and range them there. I’ve not been successful either way.

Here is my code as it stands.

{{ define "main" }}
    {{ partial "ia-top-of-page.html" . }}
    {{ .Content }}
    {{- $image := resources.Get "images/icons/rss.png" | fingerprint -}}
    {{ range (.Pages.GroupByParam "minorVersion").Reverse }}
    <h2>1.{{ .Key }}.x</h2>
    <div class="expandable-content">
        <div class="summary">
            <div class="svg-wrap"><svg class="svg-Icon" aria-hidden="true"><use xlink:href="#_sprite-plus"></use></svg></div>
            <span class="expand-link-text">Version 1.{{ .Key }}.x releases</h2></span>
        </div>
        <div class="expand-content">
            {{ range .Pages }}
            <h3>{{ .Title }} ({{ .PublishDate | time.Format ":date_long"  }})</h3>
            {{ .Content }}
            {{- end -}}
        </div>
    </div>
    {{- end -}}
{{ end }}

My front matter looks like this:

---
title: 1.22.7
publishDate: 2022-03-03
minorVersion: 22
---

My directory structure is:

├── content
│   ├── products
│   │   ├── software
│   │        ├── details
│   │              ├── changelog (notes are here)

Any help would be immensely appreciated. Thanks!

<h2>Minor version >= 18</h2>
{{ range ((where .Pages "Params.minorversion" "ge" 18).GroupByParam "minorversion").Reverse }}
  <h3>{{ .Key }}</h3>
  {{ range (.Pages.ByParam "minorversion").Reverse }}
    <h4><a href="{{ .RelPermalink }}">{{ .Title }}</a></h4>
  {{ end }}
{{ end }}

<h2>Minor version < 18</h2>
{{ range ((where .Pages "Params.minorversion" "lt" 18).GroupByParam "minorversion").Reverse }}
  <h3>{{ .Key }}</h3>
  {{ range (.Pages.ByParam "minorversion").Reverse }}
    <h4><a href="{{ .RelPermalink }}">{{ .Title }}</a></h4>
  {{ end }}
{{ end }}
2 Likes

@jmooring oh wow! Thank you so much! I obviously still have a lot to learn. You rock

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