Cant evaluate existing field

Hello,
I have a rather strange problem. I have the following front matter:

contacts:
   title: Talk to sales representative
   phones:
       - country: CH
       - country: CH
       - country: CH
        email:
            title: "You can also email us:"

I am trying to iterate the phones:

{{ range .Params.Contacts.Phones }}
    <p class="text-white">{{ .country }}</p>
{{ end }}

On this I get the error can't evaluate field country in type interface {}. I know this is caused when Im trying to call property that does not exist. However the thing is that when I call simple {{ . }} on the template it renders map[country:CH]. It is obviously mapped and its there. In addition if I remove country: in the front matter so its not object in the array element, but only array element and use {{ . }} I get the CH. I really dont understand whats going on. I tried and searched for many things, but few lines below the same structure works perfectly without any errors and its even more deep:

form:
    fields:
        - type: email
          placeholder: Email
          required: true
        - type: select 
          placeholder: Country
          options:
            - title: Austria
              data: AT
            - title: Germany
              data: DE
            - title: Switzerland
              data: CH
            - title: United kingdom
              data: UK
        - type: textarea
          placeholder: Write us
    moreinfo:
        title: Get advanced support by providing some more details
        fields:
            - type: input
              placeholder: Name
            - type: input
              placeholder: Website URL

You can put your code blocks between two lines with three backticks on each. Then you don’t have to put the backticks around everything.

Like -

Thanks. The three ` is what I was missing.

1 Like

You can wrap the 3-backticks block in a 4-backticks block to show the 3-backticks block :slight_smile:

So, you won’t see here, but I actually have the below wrapped in 4 backticks:

```
some code
```

And to show the 4-backticks block, wrap that in 5-backticks block, and so on…

2 Likes

Please dont turn this into ticks conversation. I really need help with this problem.

Keys set in Front Matter are always lowercase in your template.

{{ range .Params.contacts.phones }}
    <p class="text-white">{{ .country }}</p>
{{ end }}

Erm usually yes, but in this case this is not the problem. I tried uppercase, lowercase and a whole bunch of other things. The foreach works well if you replace {{ .country }} with {{ . }}.

Your code (lowercased) works fine on one of my projects though text is white on white.

<p class="text-white">CH</p>
<p class="text-white">CH</p>
<p class="text-white">CH</p>

Now we’re going to need to look at a repo to help you beyond that.

Great. This means its somewhere deeper. Im afraid I cant expose the whole repo as it is in local gitlab and Im not allowed to.
However I can show you a gist with the full two files. I have the suspicion that this will not be enough though.

Sorry this does not help. Maybe someone else is able to spot an error in your gist, but I was not.

Thanks a lot for the help. Hopefully someone else can spot the problem, until then Ill just try to tackle this.

your gist (copy/paste yaml FrontMatter) with

{{ .Params.Contacts.Title }}
{{- range .Params.Contacts.Phones }}
  {{ .country }}
{{- end }}
{{ index .Params.Contacts.Email.Title }}

=>

Talk to sales representative
  CH
  CH
  CH
You can also email us:
$ hugo env
Hugo Static Site Generator v0.36 linux/amd64 BuildDate: 2018-02-05T15:22:28Z
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.9.3"

your version is?

The version is the same
$ hugo env
Hugo Static Site Generator v0.36 darwin/amd64 BuildDate:
GOOS="darwin"
GOARCH="amd64"
GOVERSION=“go1.9.3”

Apparently there is something more going on here. We are using gulp for building multiple sites. Im not sure if this can be at fault. The amusing part is that literally few lines below (where I call the partial that generates form) it works without problem.

Sorry about going off on a tangent about the backticks thing.

Have you tried re-specifying the front matter in question, by re-entering the spaces? It might be that some bad character got introduced by accident.

Hey! Do you find how to resolve the problem yo have? I’m having the exact same problem and after trying everything, i cannot resolve this.