Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
Hugo won't let me list pages from a section, rejecting 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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're missing a where statement. $products is a variable

.Site.RegularPages.ByTitle <- isn't a value. 

Therefore the errors are clear, no?

But to handle your original point:

Your halfway between assigning a variable and running a function.

So:

$products := .Site.RegularPages <- existing "Array/Map/Slice" assigned to a variable

.ByTitle is a parameter to pass to a function (I believe).

If you want that grouping organized by title-which would be a function to run before assigning to a variable.

Ranges through the regular pages by title like you want:

{{range .Site.RegularPages.ByTitle}}
{{ . }}
{{ end }}

If you still want then an "array" sorted by title: See docs:

https://gohugo.io/functions/where/ (which I find to be excellent) and 
https://gohugo.io/functions/sort/#readout

You would use Sort. You could also just do this:

{{range where .Site.RegularPages.ByTitle "Section" "products" }}
 {{ . }}
{{ end }}

Or more specifically:

{{ $product := where .Site.RegularPages.ByTitle "Section" .Section }}

Summary: To answer your question: Your code isn't working because you are mixing assigning a variable with running a function.

You have almost a where statement in the assignment of the variable. That's why the errors you are receiving.

additional notes:

As I don't have access to your repo, I don't really know what you are trying to do, I would suggest you use the above docs to help you out.

The "earlier error" I think you are trying to resolve is this "with" statement of .Params.Banners as you are "dropping context" I do believe that their is faulty logic there.

However, if you still want to get around this, use "sort" to sort the value or $products (assigning it the Regular pages with the where statment).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!