Range of every other element?

I’m trying to split my lists into two columns, not based on any criteria, I just want each page to be shown in one of two columns. I don’t know much about Go, and I couldn’t find much online. Anyone know a good way for run a range for every odd element and for every even element, or something similar?

Thank you

That sounds like a job for the CSS in your theme, not for the range function.

1 Like
{{/* Column 1 */}}
{{ range $k, $_ := site.RegularPages }}
  {{ if modBool $k 2 }}
    <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
  {{ end }}
{{ end }}
  
{{/* Column 2 */}}
{{ range $k, $_ := site.RegularPages }}
  {{ if not (modBool $k 2) }}
    <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
  {{ end }}
{{ end }}
2 Likes

Or, with only one range (and CSS classes):

{{ $class := "" }}
{{ range $k, $_ := site.RegularPages }}
  {{ if modBool $k 2 }}
    {{ $class = "left-column" }}
  {{ else }}
     {{ $class = "right-column"}}
  {{ end }}
   <h2 class="{{$class}}"><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
1 Like