Range scoping problem

Hello everyone,
I have a problem once again and i couldn’t figure it out myself :confused:
maybe its just me but i think the docs are sometimes quiet hard to understand^^
So now my problem.
Im trying to create a navbar based on frontmatter and the folder structure.
Thats my navbar code:

 {{ range $.Site.Pages }}
                {{ if .Params.navbar }}
                  {{ if  .Params.dropdown }}
                    <div class="dropdown">
                      <li class="navbtn"><a href="{{ .URL }}/">{{ .Name }}</a></li>
                      <div class="dropdown-content">
                          {{ range .Params.dropdown }}
                            <div class="col-md-6">
                             <h1>{{.}}</h1>
                             {{ $scope := .}}
                              {{ range where $.Pages "Section" "{{.}}" }}
                                {{ if .Params.clickable }}
                                  <a href="{{$scope.RelPermalink}}">{{$scope.Params.title}}</a>
                                {{ else }}
                                  <a href="#">{{$scope.Params.title}}</a>
                                {{ end }}
                              {{ end }}
                            </div>
                          {{ end }}                        
                      </div>
                    </div>
                  {{ else  }}
                    <li class="navbtn"><a href="{{ .URL }}/">{{ .Name }}</a></li>
                  {{ end }}
                {{ end }}
              {{ end }}

My problem is that it doesn’t show an error but also doesn’t show anything after
{{ range where $.Pages “Section” “{{.}}” }}
I already tried it without the {{ $scope := .}} and it didn’t make a difference.

Thank in advance :slight_smile:

also i have no idea how to format code here^^

{{ range where $.Pages "Section" "{{.}}" }}

Unless your section’s name is litteraly those curlies and this dot, you should write:

{{ range where $.Pages "Section" . }}

Your dot being the value of a .Params.dropdown entry, if this is a string then it should work I suppose… But you should look into with

1 Like

It works now. i cant belive i didn’t try this in the 3 hours i was woking on this^^
Thank you very much. :slight_smile:

1 Like

@regis This seems like a pretty common use case. Think there’s value in adding this example to the range page? I know it’s on the templating introduction page too, of course.

Oh, I am not sure which use case you are referring to? The range where syntax?

Sorry, should have been clearer; i.e. range pointing to site/global or local variables. The latter is already included in the intro to templating, but easier reference for people using range. Not a firm consideration, TBH, but thinking aloud (in type).