# \[Solved\]Delimit map from data file

**URL:** <https://discourse.gohugo.io/t/solved-delimit-map-from-data-file/4800>\
**Category:** support\
**Created:** [December 12, 2016, 3:40pm UTC](https://discourse.gohugo.io/t/solved-delimit-map-from-data-file/4800 "2016-12-12T15:40:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![justrjlewis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/justrjlewis/32/987_2.png) [@justrjlewis](https://discourse.gohugo.io/u/justrjlewis)\
**Post date:** [December 12, 2016, 3:40pm UTC](https://discourse.gohugo.io/t/solved-delimit-map-from-data-file/4800/1 "2016-12-12T15:40:14Z")

</div>

To start, in data/products, I have product.toml with the a map for color values like this:

```auto
[color]
[[color.logo]]
name = "blue"
cid = "blue"
images = "http://placehold.it/330x508"

[[color.logo]]
name = "Green"
cid = "green"
images ="http://placehold.it/330x508"

[[color.product]]
name = "Black"
cid = "black"
images = ""

```

In my product.html, I’m trying to get the colors listed with a delimiter ("|"). I read something about not being able to delimit range output, which I can confirm that I did not get working so I switched to this:

```auto
{{ $lc := .Site.Data.products.color.logo }}
{{ if isset $lc .cid }}
  {{ delimit (index $lc .cid) "|" }}
{{ end }}

```

That keeps returning a blank.

Any ideas what I’m missing, or how I can get this to work?  
Also, is it possible to have/manipulate an array as one of the key, value pairs in the map? That’s my next thing to tackle

example:

```auto
[color]
[[color.logo]]
images = ["image1","image2"]

```

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [December 12, 2016, 9:03pm UTC](https://discourse.gohugo.io/t/solved-delimit-map-from-data-file/4800/2 "2016-12-12T21:03:49Z")

</div>

Check your usage of `isset` and `index`. Second parameter should be a string of the field name.

```auto
{{ if isset $lc "cid" }}
{{ delimit (index $lc "cid") "|" }}

```

---

<div class="post-metadata">

**Author:** ![justrjlewis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/justrjlewis/32/987_2.png) [@justrjlewis](https://discourse.gohugo.io/u/justrjlewis)\
**Post date:** [December 12, 2016, 10:37pm UTC](https://discourse.gohugo.io/t/solved-delimit-map-from-data-file/4800/3 "2016-12-12T22:37:04Z")

</div>

Thank you, but that still isn’t yielding anything.

using range gives me a list, but in the wrong format

```auto
{{ range $index, $lc := .color.logo }}
   {{ $options := index $lc "cid" }}
   {{- $options -}}
 {{- end -}}

```

renders:

```
          blue
          green
          black   

```

I need: blue|green|black

---

<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:** [December 12, 2016, 11:01pm UTC](https://discourse.gohugo.io/t/solved-delimit-map-from-data-file/4800/4 "2016-12-12T23:01:25Z")

</div>

> **[Howto: Delimiter separated tags](https://discourse.gohugo.io/t/howto-delimiter-separated-tags/146)**
>
> The construction below looks counter-intuitive, but it works: Given: Tags = \['item1', 'item2', 'item3'\] This: {{ range $i, $e := .Params.tags }}{{ if $i }}, {{ end }}{{ $e }}{{ end }} Gives: item1, item2, item3 The example above uses tags...

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [December 12, 2016, 11:40pm UTC](https://discourse.gohugo.io/t/solved-delimit-map-from-data-file/4800/5 "2016-12-12T23:40:47Z")

</div>

True. The problem is that `delimit` wants all the values at once, and you’re iterating over them one at a time.

Untested, but see if you can make this work:

```auto
{{ range $index, $lc := .color.logo }}
{{ $options := index $lc "cid" }}
{{ $.Scratch.SetInMap "colors" $options $options }}
{{ end }}
{{ delimit $.Scratch.GetSortedMapValues "colors" }}

```

---

<div class="post-metadata">

**Author:** ![justrjlewis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/justrjlewis/32/987_2.png) [@justrjlewis](https://discourse.gohugo.io/u/justrjlewis)\
**Post date:** [December 14, 2016, 7:19pm UTC](https://discourse.gohugo.io/t/solved-delimit-map-from-data-file/4800/6 "2016-12-14T19:19:03Z")

</div>

For some weird and unknown reason I wasn’t able to get the Scratch method to work anywhere in the partial for any reason. I even tried just using the scratch examples from the [docs](https://gohugo.io/extras/scratch/) without directly referencing the info from the data files like:

```auto
{{ $.Scratch.SetInMap "colors" "c1" "blue" }}

```

Any ideas on what I was doing wrong with that? I think delimit wasn’t working because the docs advise that it works on lists, groups, terms, and taxonomies - I didn’t initially take that to mean **only** , but here we are.

I did get @bep’s suggestion working:

```auto
{{ range $index, $lc := .color.logo }}
  {{ $option := index $lc "name" }}
  {{ if $index }}| 
  {{ end }}
  {{ $option }}
{{ end }} <!-- end color logo range -->

```

Thanks for the help guys!
