WeightedPages.Pages and Partial Templates

I have the following template code which works correctly when I put it in the index.html file in the layouts/ folder. However, when I make it into a partial template, it fails with can't evaluate field Pages in type []interface {}.

  {{ $ptypes := $.Site.Taxonomies.length }}
  {{ $posts := ($ptypes.short | union $ptypes.long | union $ptypes.verylong).Pages }}
  {{ if $.IsHome }}
    {{ $posts = $ptypes.long.Pages }}
  {{ end }}

  {{ range $posts.GroupByDate "2006" }}
      <h3>{{ .Key }}</h3>
      {{ range .Pages }}
        <li>{{ partial "post-listing" . }}</li>
      {{ end }}
  {{ end }}

As far as I can make out I have used the $ variable to ensure that gobal variables brought forward correctly. What is going wrong here?


Are you passing on the “dot” context to the partial call? https://gohugo.io/templates/partials/#use-partials-in-your-templates

Yes. I am passing it like so {{ partial "post-bydate-listing" . }}

In that case, do you have a sample repo we can look at? We don’t need all the code, just enough to reproduce this error. I tried your snippet, going by your description, and the only way I can get it to produce the exact error is when the dot is not being passed.

Hey @trojan … doesn’t the partial have an extension? Like

{{ partial “partial-filename.html” . }}

That seems to have done the trick. No wonder I was not able to replicate the problem in a blank project. Thanks!