Can data structure affect the output?

In my english-only site I used a data file with a structure:

  - tag: value1
  - tag: value2
  - tag: value3
  - tag: value4

and it was selected with:

<option value="{{ .tag }}">{{ .tag }}</option>

and everything was fine. But next I implemented localization and turned my data file into

  - tag0: english value1
  - tag1: localized value1
  - tag0: english value2
  - tag1: localized value2

and it is now selected with

<select class="form-control" id="tags" name="tags" size="1" required>
    {{ $tagsData := index $sellData $.Params.categories }}
    <option value="" disabled selected>{{ .tagVal }}</option>
    {{ range $tagsData }}
        <option value="{{ .tag0 }}">{{ .tag1 }}</option>
    {{ end }}
</select>

The problem is, the output is present only on every other line:

data
empty line
data
empty line

I’m puzzled.

Things like {{ range $tagsData }} will add an empty line unless you add hyphens to remove the whitespace, {{- range $tagsData -}}.

Thank you Frederik, but {{- range $tagsData -}} does not help.

Did you add the hyphens on all the template tags?

Yes, I added to range, and I tried to add to {{- .tag0 -}} and {{- .tag1 -}}:

<select class="form-control" id="tags" name="tags" size="1" required>
  {{ $tagsData := index $sellData $.Params.categories }}
  <option value="" disabled selected>{{ .tagVal }}</option>
  {{- range $tagsData -}}
    <option value="{{ .tag0 }}">{{ .tag1 }}</option>
  {{ end }}
</select>

I don’t understand what you are doing, and I don’t want to, but the above looks wrong. Visualized as JSON:

[
  {
    "tag0": "english value1"
  },
  {
    "tag1": "localized value1"
  },
  {
    "tag0": "english value2"
  },
  {
    "tag1": "localized value2"
  }
]

You have an array of 4 elements. I think you want an array of 2 elements, with each element containing two keys.

Exactly. I’ve already understood that, but I don’t know why it happens and how to make it an array of 2 elements

Rewrite your data file or whatever is driving this.

Yes, I’m already doing that. Thatnk you

Does that mean that you have resolved the problem, or do you need additional assistance?

I guess what you meant to do is a list of objects with two keys each:

- tag0: english value1
  tag1: localized value1
- tag0: english value2
  tag1: localized value2