# Range over slice

**URL:** <https://discourse.gohugo.io/t/range-over-slice/766>\
**Category:** support\
**Created:** [February 22, 2015, 2:06pm UTC](https://discourse.gohugo.io/t/range-over-slice/766 "2015-02-22T14:06:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gridindex](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/gridindex/32/183_2.png) [@gridindex](https://discourse.gohugo.io/u/gridindex)\
**Post date:** [February 22, 2015, 2:06pm UTC](https://discourse.gohugo.io/t/range-over-slice/766/1 "2015-02-22T14:06:45Z")

</div>

I’d like to range over a slice from an array within a template.

Hugo offers this nice function:

```
{{ range first 10 array }}
<!-- range [2:10] array -->
{{ end }}

```

Instead of retrieving all ten items of the array I wanted to retrieve second till tenth [2:10]

Is there a way in hugo?

thanks in advance

---

<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:** [February 22, 2015, 2:18pm UTC](https://discourse.gohugo.io/t/range-over-slice/766/2 "2015-02-22T14:18:04Z")

</div>

I think you currently have to add a conditional for the index (range $index, $element …) inside the loop.

---

<div class="post-metadata">

**Author:** ![gridindex](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/gridindex/32/183_2.png) [@gridindex](https://discourse.gohugo.io/u/gridindex)\
**Post date:** [February 22, 2015, 4:09pm UTC](https://discourse.gohugo.io/t/range-over-slice/766/3 "2015-02-22T16:09:15Z")

</div>

I did, like this example shows:

```
{{ range $index, $element := .Params.slideshow }}
    {{ if $index eq 1 }}   
      {{ $element.head_title }}
    {{ else }} 
      {{ $element.title }}
    {{ end }}
{{ end }}

```

But this produces an error:

```
can't give argument to non-function $index

```

Any hints?

thanks in advance

---

<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:** [February 22, 2015, 4:41pm UTC](https://discourse.gohugo.io/t/range-over-slice/766/4 "2015-02-22T16:41:26Z")

</div>

> [@gridindex](#):
>
> {{ if $index eq 1 }}

{{ if eq $index 1 }}

---

<div class="post-metadata">

**Author:** ![spf13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/spf13/32/37_2.png) [@spf13](https://discourse.gohugo.io/u/spf13)\
**Post date:** [February 22, 2015, 4:55pm UTC](https://discourse.gohugo.io/t/range-over-slice/766/5 "2015-02-22T16:55:00Z")

</div>

That’s not how go templates order function calls. You need to change around the order of that if statement. There’s examples in the docs.

Steve Francia[spf13.com](http://spf13.com)@spf13

---

<div class="post-metadata">

**Author:** ![gridindex](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/gridindex/32/183_2.png) [@gridindex](https://discourse.gohugo.io/u/gridindex)\
**Post date:** [February 22, 2015, 6:24pm UTC](https://discourse.gohugo.io/t/range-over-slice/766/6 "2015-02-22T18:24:53Z")

</div>

Excuse me! Read the docs first 😉

Now everything is working as expected.  
Thanks @bjornerik and @spf13 for the quick and helpful support.

By the way: Hugo is great!

Cheers
