.Site.RegularPages.ByTitle won't take arguments?

layouts/index.html:

{{define "main"}}
{{ $products := .Site.RegularPages.ByTitle "Section" "products" }}
{{with .Params.banner}}
[...]
              <div class="dropdown-menu">
                  {{ range (where $products ) }}
                    <a class="dropdown-item " href="{{ .Permalink }}">{{ .Title }}</a>
                  {{ end }}
[...]

Produces this error:

ERROR: executing "main" at <.Site.RegularPages.ByTitle>: wrong number of args for ByTitle: want 0 got 2

Okay, so let’s try removing those two (necessary) arguments I guess?

{{ $products := .Site.RegularPages.ByTitle }}

Now, the error says:

ERROR: executing "main" at <where>: wrong number of args for where: want at least 2 got 1

What’s going on here? The first bit of code works in my layouts/header.html just fine, but now Hugo seems to be confused.

Should be:

{{define "main"}}
{{ $products := .Site.RegularPages.ByTitle }}
{{with .Params.banner}}
[...]
              <div class="dropdown-menu">
                  {{ range (where $products "Section" "products" ) }}
                    <a class="dropdown-item " href="{{ .Permalink }}">{{ .Title }}</a>
                  {{ end }}
[...]

“Section” and “products” are arguments to where not .Site.RegularPages.ByTitle (which has no arguments)

Alternatively:

{{define "main"}}
{{ $products :=  where (.Site.RegularPages.ByTitle) "Section" "products" }}
{{with .Params.banner}}
[...]
              <div class="dropdown-menu">
                  {{ range $products }}
                    <a class="dropdown-item " href="{{ .Permalink }}">{{ .Title }}</a>
                  {{ end }}
[...]

which probably is more what you meant.

1 Like