How to pass variables to a partial template?

I know this is an old topic but it was the top search result for this problem so I’ll add my solution. I’m able to pass both the context and a variable to a partial and use both inside the partial this way.

Including the partial:

{{ partial "partialFileName" (dict "context" . "myVar" "val") }}

Accessing the variable inside the partial:

{{ .myVar }}

But then everything you would normally reference through the . changes to use .context:

{{ .context.Title }}
{{ .context.Scratch.Get "myScratchVar" }}

3 Likes