# Loop multiple arrays into a range

**URL:** <https://discourse.gohugo.io/t/loop-multiple-arrays-into-a-range/15711>\
**Category:** support\
**Created:** [December 7, 2018, 6:55pm UTC](https://discourse.gohugo.io/t/loop-multiple-arrays-into-a-range/15711 "2018-12-07T18:55:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emma\_Stone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/emma_stone/32/18391_2.png) [@Emma\_Stone](https://discourse.gohugo.io/u/Emma_Stone)\
**Post date:** [December 7, 2018, 6:55pm UTC](https://discourse.gohugo.io/t/loop-multiple-arrays-into-a-range/15711/1 "2018-12-07T18:55:13Z")

</div>

Dear Hugo community,

I just started with Hugo and wanted to know how to loop multiple arrays into a range?

This is what I have in my Front matter:

```
---
title: "Billy"
img: [“img1.jpg”, “img2.jpg”]
---

```

And my range:

```
 {{ range .Params.img }}
        <img src="{{ . }}" alt="{{ .Title }}">
    {{ end }}

```

But Iget an error as it can’t find .Title? I am setting up a test repo now but just wanted to know if it was possible to have multiple arrays in a range?

Sorry for the messy code still getting used to this page.

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [December 7, 2018, 7:08pm UTC](https://discourse.gohugo.io/t/loop-multiple-arrays-into-a-range/15711/2 "2018-12-07T19:08:55Z")

</div>

So this part is right

```nohighlight
{{ range .Params.img }}

```

But this is incorrect

```nohighlight
alt="{{ .Title }}"

```

When you loop through that map of images, each item is a string. So a string doesn’t have a title. Maybe this is what you want

```nohighlight
alt="{{ . }}"

```

---

<div class="post-metadata">

**Author:** ![Emma\_Stone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/emma_stone/32/18391_2.png) [@Emma\_Stone](https://discourse.gohugo.io/u/Emma_Stone)\
**Post date:** [December 7, 2018, 7:10pm UTC](https://discourse.gohugo.io/t/loop-multiple-arrays-into-a-range/15711/3 "2018-12-07T19:10:19Z")

</div>

@zwbetz thank you for the quick reply! Amazing! I tried `{{ . }}` but then I just see img1.jpg and so on, I wanted to have Billy as the alt tag?!

Or can I have`img: [“img1.jpg”, “img2.jpg”]` and then `img_alt: [“img1 Alt”, “img12 Alt”]` ?

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [December 7, 2018, 7:15pm UTC](https://discourse.gohugo.io/t/loop-multiple-arrays-into-a-range/15711/4 "2018-12-07T19:15:13Z")

</div>

So when you loop through that img param, the context of the dot changes. So you need to grab title before you’re inside the loop

```auto
{{ $title := .Title }}
{{ range .Params.img }}
  <img src="{{ . }}" alt="{{ $title }}">
{{ end }}

```

Read more about [scope, dot, and context here](https://regisphilibert.com/blog/2018/02/hugo-the-scope-the-context-and-the-dot/)

---

<div class="post-metadata">

**Author:** ![Emma\_Stone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/emma_stone/32/18391_2.png) [@Emma\_Stone](https://discourse.gohugo.io/u/Emma_Stone)\
**Post date:** [December 7, 2018, 7:16pm UTC](https://discourse.gohugo.io/t/loop-multiple-arrays-into-a-range/15711/5 "2018-12-07T19:16:10Z")

</div>

This is what I am looking for!! Thank you so much, I need to do a lot more reading! You’re a gentleman! Thanks again,
