How can I use "if in" with an array or list?

Hi,

I have the following code in my “index.html” and it’s working just fine, from within a “range” so $index is correctly incrementing with each page that’s being iterated.

      {{ if eq $index 0 }}
        {{ $.Scratch.Set "colSpan" 4 }}
        {{ $.Scratch.Set "rowSpan" 4 }}
      {{ else if in $index 1 }}
        {{ $.Scratch.Set "colSpan" 2 }}
        {{ $.Scratch.Set "rowSpan" 2 }}
      {{ else if in $index 2 }}
        {{ $.Scratch.Set "colSpan" 2 }}
        {{ $.Scratch.Set "rowSpan" 2 }}
      {{ else }}
        {{ $.Scratch.Set "colSpan" 1 }}
        {{ $.Scratch.Set "rowSpan" 1 }}
      {{ end }}

It lets my highlight my latest posts, showing the first page with a 4x4 size, the next two with 2x2 size, and everything older than that with a 1x1 size.

Is there a way to use the “if in $index …” in a way that means I don’t have to have a separate if/else clause for both of the 2x2 options? Something like “if in $index (1 2)”? I’ve tried that and it doesn’t work.

I’m not exactly sure what you’re trying to accomplish, but the signature for the in function is

in SET ITEM

not

in ITEM SET

Thanks jmooring, I’ve swapped the arguments round but I’m still not sure of the correct syntax. Any ideas?

I’ve tried the following but neither work:

{{ else if in (1, 2) $index }}
{{ else if in (1 2) $index }}

I’ve got it, you have to use slice:

{{ else if in (slice 1 2) $index }}

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