# Attaching an index to a {{ range }}

**URL:** <https://discourse.gohugo.io/t/attaching-an-index-to-a-range/1792>\
**Category:** support\
**Created:** [September 27, 2015, 7:22am UTC](https://discourse.gohugo.io/t/attaching-an-index-to-a-range/1792 "2015-09-27T07:22:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jer](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@jer](https://discourse.gohugo.io/u/jer)\
**Post date:** [September 27, 2015, 7:22am UTC](https://discourse.gohugo.io/t/attaching-an-index-to-a-range/1792/1 "2015-09-27T07:22:26Z")

</div>

Hi all.

I’m making a material design theme for hugo. On the frontpage, I want to render the most recent post with a certain template, and the 2nd to 10th most recent posts with a different template.

So far I have:

```auto
{{ range first 10 (where .Site.Pages "Section" "post") }}  
        {{ .Render "card" }}
{{ end }} 

```

How can I modify the above code to accomplish this? Is there a way to attach an `index` so I could do something like:

```auto
{{ range first 10 (where .Site.Pages "Section" "post") }}
    {{if eq index 1}}
        {{ .Render "card1" }}
    {{else}}
        {{ .Render "card2" }}
    {{end}}
{{ end }} 

```

I’m new to Go, and haven’t had much luck googling around. Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 27, 2015, 9:30am UTC](https://discourse.gohugo.io/t/attaching-an-index-to-a-range/1792/2 "2015-09-27T09:30:15Z")

</div>

> [@jer](#):
>
> {{ range first 10 (where .Site.Pages “Section” “post”) }}

Something like this:

```auto
{{ $index, $element := range first 10 (where .Site.Pages "Section" "post") }}

```

Note that the $index is zero-based.

---

<div class="post-metadata">

**Author:** ![jer](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@jer](https://discourse.gohugo.io/u/jer)\
**Post date:** [September 27, 2015, 5:25pm UTC](https://discourse.gohugo.io/t/attaching-an-index-to-a-range/1792/3 "2015-09-27T17:25:14Z")

</div>

Ah, thanks Bep. I had tried attaching $index previously, but I must of used wrong syntax.

I got it to work using the following snippet:

```auto
{{ range $index, $element := first .Site.Params.frontpageposts (where .Site.Pages "Section" "post") }} 
    {{ if (eq $index 0) }}
        {{ .Render "card-8" }}
    {{ else }}
        {{ .Render "card-12" }}
    {{ end }} 
{{ end }}

```

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [August 5, 2020, 12:25am UTC](https://discourse.gohugo.io/t/attaching-an-index-to-a-range/1792/4 "2020-08-05T00:25:23Z")

</div>

A post was split to a new topic: [Using index with range](https://discourse.gohugo.io/t/using-index-with-range/27364)

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [August 5, 2020, 12:25am UTC](https://discourse.gohugo.io/t/attaching-an-index-to-a-range/1792/5 "2020-08-05T00:25:33Z")

</div>


