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.
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).