Error calling where: can't iterate over nil in Partial

Hello all.

I have been trying to use Partials to generate some data from my files.

Here is the call to the partial -
{{ partial "print_topLevel.html" (dict "context" . "secName" "00_dept_a" "codeID" "00-dept-01") }}

and here is the partial stored in (/layouts/partials/print_topLevel.html) file.

<!--Testing if parameters are actually being passed -->
{{ $secName := .secName }}
{{ $codeID := .codeID }}
{{ $secName }}<br>
{{ $codeID }}<br>
<!-- Above works Good -->

<!--Fetch the MD file from the $secName folder for the specified code_ID in $codeID-->
{{ $topLevel := where (where .site.Pages "Section" $secName) "context.Code_ID" "eq" $codeID }}
<!--Display the Contents / Front Matter of this file-->
{{- range $topLevel -}}

    <h1>{{ .context.ID_Name }}</h1>
    <p><strong>Code ID:</strong> {{.context.Code_ID }}</p>
    <p><strong>Full Name:</strong> {{.context.fullName }}</p>

{{- end -}}

I have also tried using the $.Site.Pages, $.context.Site.Pages and $ but it has failed on all counts.
With the above I am getting the error -

execute of template failed at <where .site.Pages "Section" $secName>: error calling where: can’t iterate over <nil> 

Any ideas how I can fix this partial so that it would work good for the data that I have?

Thank you for your time to read out and trying to help.

Warm regards,

site.RegularPages – no leading dot

1 Like

Sir, thank you once again, you have been a life saver for me.

A couple of things -
I read that we could use the global site variable. So I experimented with site.Pages (as you could see my last code that I placed on the thread). Any specific reasons why I should be using the .RegularPages here and not .Pages?

Also on another note, after I changed to site.RegularPages, the code still gave me error -

 <.context.Code_ID>: can't evaluate field context in type page.Page

So I changed it to .Params.Code_ID etc and it worked fine.

the “context” in the dictionary was set to the . during the call. So shouldn’t have this worked?

Thanks again sir for being there. I dont know about others, but personally, I feel indebted to you because on 99% of my problems, you have been the one who has showed me a way out and helped me learn some as well.


No. The full descriptor is .Page.Params.Code_ID. You passed the .Page part of it, so you need to provide the rest (i.e., .Params.Code_ID).

With this content structure:

├── books/
│   ├──
│   └──


{{ range site.Pages }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

Produces this:

Book 2
Book 1

While this:

{{ range site.RegularPages }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

Produces this:

Book 2
Book 1
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.