Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

298
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda