Cant evaluate existing field

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

   title: Talk to sales representative
       - country: CH
       - country: CH
       - country: CH
            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:

        - type: email
          placeholder: Email
          required: true
        - type: select 
          placeholder: Country
            - title: Austria
              data: AT
            - title: Germany
              data: DE
            - title: Switzerland
              data: CH
            - title: United kingdom
              data: UK
        - type: textarea
          placeholder: Write us
        title: Get advanced support by providing some more details
            - 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…


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
You can also email us:
$ hugo env
Hugo Static Site Generator v0.36 linux/amd64 BuildDate: 2018-02-05T15:22:28Z

your version is?

The version is the same
$ hugo env
Hugo Static Site Generator v0.36 darwin/amd64 BuildDate:

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.