[solved] groupByDate groups by month. How to group by date (day)?

Here’s what I’ve got working so far, which only groups by month. How can I group by day?

              {{ range .Data.Pages.GroupByDate "2006-01-01" }}
                  {{ dateFormat "Jan 2 2006" .Key }}
                  {{ range .Pages }}
                      <h4>{{ range .Params.classes}}{{ . }}{{ end }} |
                      <a href="{{ .Permalink }}">{{ .Title }}</a>
                      {{ .Summary }}
                  {{ end }}
                {{ end }}
1 Like

Here’s what finally worked:

 {{ range .Data.Pages.GroupByDate "Monday, Jan 2, 2006" }}
 {{ $page := index .Pages 0 }} <!-- Each group has at least 1 page -->
  <h3><i class="fa fa-calendar-o"></i> {{ .Key }}</h3>
  {{ range .Pages.ByDate }}
  {{ if ge $page.Date.Unix now }} <!-- Hide the past? -->
  {{ $link := .Permalink }} <!-- Grab it or lose it. -->
    <div class="lesson-listing">
    <h4>{{ range .Params.classes}} {{ . }} {{ end }} |
    <a href="{{ .Permalink }}">{{ .Title }}</a></h4>
    <p class="intro">{{ .Summary }}</p>
     {{ if .Params.Pdf }}
     {{ range .Params.Pdf }}
       <p><i class="fa fa-file-pdf-o"></i>
       <a href="/lesson/pdf/{{ . }}" target="_blank">{{ . }}</a><p>
     {{ end }} <!-- range .Params.Pdf -->
     {{ end }} <!-- if .Params.Pdf -->
  {{ end }} <!-- if ge $page.Date.Unix now -->
 {{ end }} <!-- range .Pages.ByDate -->
{{ end }} <!-- range .Date.Pages.GroupedByDate -->
1 Like

Just curious if perhaps you’re missing a class= here…

Also, I think you can skip this: {{ if .Params.Pdf }} and just go straight to range…I wouldn’t recommend this in every use case for ranging through potentially empty FM arrays, but everything is contained within the loop, so if it’s empty or not even mentioned, you’re still okay…

What do you mean by “Hide the past?” Are you running hugo with --buildFuture

That refers to educational classes, not css. :slight_smile:

OK. Thanks.

No, not using -- buildFuture. I’m using if ge $page.Date.Unix now to only show pages with dates greater than now. At least that’s what I think I’m doing. Have to add more test pages to be sure.

Haha, oops. Gotcha :smile:

I think that’s where I was confused. I believe gt takes this into account already with .Unix since it treats .Date as a date, but either way should work.

And I confused myself on this one, sorry about that: --buildFuture is only related to publishdate, whereas you can set date in the future and the page will still render…

“Hide the past” was just me trying to be funny. Figured I’d be the only one to see that particular joke. But as history demonstrates with depressing regularity, the past is amazingly good at rising up and convoluting the present whenever we least expect it.