Error Passing Data into Partials

We are including a partial into all of our page layouts and now I would like to be able to pass data into that partial. However, I am getting some errors and not finding the clarity from the docs to get around this…

This implementation throws errors on other elements in the partial, like: {{ .Title | markdownify }}

layout ---
{{ partial "post-meta--feedback" (dict "post_type" "article") }}

partial ---
{{ .post_type }}

If I add the period into the partial include (like the following),I get the error can't evaluate field post_type

layout ---
{{ partial "post-meta--feedback" . (dict "post_type" "article") }}

partial ---
{{ .post_type }}

And insight on how to get this working would be much appreciated.

The partial takes only 2 arguments:

  1. Partial file name
  2. Context

So you cannot do {{ partial "post-meta--feedback" . (dict "post_type" "article") }}, but you can do {{ partial "post-meta--feedback" (dict "page" . "post_type" "article") }}.

Then in the partial, you do .page.Title instead of .Title.

See also the section Top level $ from partial from that excellent post by @regis… that uses the exact same example of using the Page context within the partial, along with other vars.

1 Like

Oh wonderful. I get it. Pass the context into the partial with "page" .

Thank you! :tada: