Conditionnal Range Data : Css Class at N elements

Hi,

I would like to have a css class at n element .

this is my code

{{ range $i, $e := ($.Site.Data.citylist.cityList) }}
    <li {{ if $i gt 52 }} class="maClass" {{ end }} >
      <a href="{{ .url }}">
        <article>
          <p>{{ .name }} {{ .departement }}{{ .region }} {{ .country }} </p>
        </article>
      </a>
    </li>
    {{ end }}

Hugo send me :

can't give argument to non-function $i

What i have missing ?

Thks.

1 Like

{{ if gt $i 52 }}

1 Like

I’m such a …

Thx

How very cool!

Here 's my spin on this to add a title before the first post of a section and another one before the second post.

{{ range $i, $e := (.Data.Pages) }}
                       <div class="post-item {{ delimit .Params.tags " " }}">
                       {{ if lt $i 1 }}<h2><span>Current Exhibition</span></h2>{{ end }}
                       {{ if eq $i 1 }}<h2><span>Past Exhibitions</span></h2>{{ end }}
                      ..............
                      {{ end}}
1 Like

ProTip:

In the event you don’t want to use pseudoselectors, mod and modBool come in handy when you want to do things like alternating rows, everything 5th div, etc…