Equivalent code to ifchanged Django template tag

Thanks, @divinerites — your solution worked, but what I really needed was a little bit different from my question, and I only realized it after further thought; What I wanted was the equivalent of Django’s {% if not forloop.first %} template tag — a way to skip the first item in a range, specifically so that a date line would only appear after the first post in a list.

This is the solution that worked for me, with help from this post:

{{ $.Scratch.Set "counter" 0 }}
{{ range .Site.RegularPages.GroupByDate "Monday, 2 January 2006" }}
  {{ $.Scratch.Set "counter" (add ($.Scratch.Get "counter") 1) }}    
  {{ if ne ($.Scratch.Get "counter") 1 }}
    <h2 class="dateline">{{ .Key }}</h2>
  {{ end }}
    …display articles, etc…
{{ end }}

Thanks for your help!

1 Like