Troubling Build error trying to access Page.Params.x.x

I get the build error:

Failed to render pages: render of "section" failed: "C:\Users\scottd\Documents\GitHub\rhino-documentation\quickstart\layouts\guide\list.html:11:21": execute of template failed: template: guide\list.html:11:21: executing "main" at <.name>: can't evaluate field name in type string

I get this error if I use hugo server -D the first time I start the server. But, if I remove the offending code start the server, then add the code back in, the server will happily serve up the string with .name listed above. Normally I simply remove .name.

And I get this error anytime hugo server -D --disableFastRender, whether it is a first build or incremental build. So, I figure this is an initialization problem. Anyone can guess why it works to walk through the .groups when the server has already been initialized, but at startup the same code fails?

I have an index page that contains this front matter:

---
title: "Modeling"
date: 2020-03-06T09:19:12-08:00
draft: true
TableOfContents: true
type: guide
groups: 
- name: "getting started"
  thumbnail: "getting-started.jpg"
- name: "basic"
  thumbnail: "basic.jpg"
- name: "fundamentals"
  thumbnail: "fundamentals.png"
- name: "project"
  thumbnail: "project.jpg"
- name: "guides"
  thumbnail: "guides.png"
---

Here is a simplified version of the range I am walking through that shows the problem:

<div class="gallery-container">
   {{ range .Params.groups }}
        Name - {{ .name }}
    {{ end }}
</div>

I hope this is enough information.

My guess is that you do not have .Params.groups in all list pages and hence Hugo fails because the code is in the list.html template.

You need to perform a check for the existence of this parameter.

Something like:

{{ with .Params.groups }}
{{ range . }}
<--- template code  --->
{{ end }}
{{ end }}

If the above does not solve your problem then you would need to share a sample repo that reproduces the issue for people in this forum to have a look at the full context of the project’s templates.

1 Like

Thank you for the response. I did try the with statement. It did not avoid the error. The problem is that the Params.groups does return a structure and it looks right. But the .name and .thumbnail do not seem to want to deliver a string. Unless I make the change after the server is already running in FastRender mode.

I setup a simple site structured with the same front matter here: https://github.com/scotttd/hugo-params-build-test

Unfortunately, the simple site above seems to work fine. Although, it does show how the site is setup.

Do you think it is a timing issue at startup? Or could it be the order things are being read? I added some image processing the other day and am wondering if that sufficiently is slowing down the build. Currently the site only takes 293 ms

Sometimes for complex projects setting a timeout in the project config might help.
e.g. timeout = 60000

If you generate the project’s /resources/ locally and then commit the build time should remain the same as before.

I know this seems like I am chasing something that is probabl

So a was able to

{{ $prtName := printf "%s%s" . }}
           <li>Name - {{ $prtName }}</li>

The results i get are this:

  1. Name - map[name:getting started thumbnail:getting-started.jpg]%!s(MISSING)
  2. Name - map[name:basic thumbnail:basic.jpg]%!s(MISSING)
  3. Name - map[name:fundamentals thumbnail:fundamentals.png]%!s(MISSING)
  4. Name - map[name:project thumbnail:project.jpg]%!s(MISSING)
  5. Name - map[name:guides thumbnail:guides.png]%!s(MISSING)

Is that a valid map? Anything look odd?

What is odd is if I can get it to work or not work, the printf of the map structure is no different. The array seems to be no different if it works or not. It is the member .xxxx method that is failing?

The map looks valid to me. But instead of printing it you can use the range function once more to get the map values.

It’s difficult to say since the sample repo does not reproduce the problem.

Yes, unfortunately I cannot get this problem in the test site. I realizes that limits what we can do.

I did drop in another range and an error that reflects the problem happens, but the error is different. So, if I build from scratch I get the error:

Error: Error building site: failed to render pages: render of "section" failed: 
"C:\Users\scottd\Documents\GitHub\rhino-documentation\quickstart\layouts\guide\list.html:13:25": 
execute of template failed: template: guide\list.html:13:25: executing "main" at <.>: range can't iterate 
over getting started

But, like the failed to get a string error. If I add the range function in after the server is running, I can range through the array with no problems. And the results are strings.

Same error if I try a range to assign to variables: {{ range $name, $value := . }}

So strange.

Actually there was no need for an extra range.

With the following:

      {{ with .Params.groups }}
            {{ range . }}
                  <li>Name - {{ .name }}</li>
                  <li>Thumb - {{ .thumbnail }}</li>
            {{ end }}
      {{ end }}

I am able to output the map values


    Name - getting started
    Thumb - getting-started.jpg
    Name - basic
    Thumb - basic.jpg
    Name - fundamentals
    Thumb - fundamentals.png
    Name - project
    Thumb - project.jpg
    Name - guides
    Thumb - guides.png

Also you need to set draft = false for the page to generate properly.

I was able to work around this problem by creating better Taxonomy page bundles by using _index for the Taxonomy location. Then I was able to store the taxonomy resources there.

Now I simply keep a list of taxonomy terms I want to list on the page.

Hugo is sure powerful.