Variables not available in partials?

I can’t figure out what I’m doing wrong, but if I move the same template code to a partial and include it back into the original file, it seems that the partial doesn’t have access to any variables.

E.g. if I have this in a template it works fine:

<title>{{ .Title }} | {{ .Section }} | {{ .Site.Title }}</title>

But if I move that into a partial and replace it with {{ partial "header.html" }}, then those three variables all become empty. The partial is definitely found and included as the general markup in it appears, but the variables all seem to be empty.

What should I be doing to get variables in partials?

Another one figured out… I need the trailing dot to pass the context to the partial:

{{ partial "header.html" . }}

not work in a partial: {{ ( index $.Site.Data.translations $.Site.Params.locale ).someField }}

1 Like

Same here:
<link rel="stylesheet" href='/css/{{ index .Site.Data.css.hash "main.css" }}'>

You cannot pass template variables in a string .

Found the issue. I should read the error messages more carefully next time.

The error was being caused at another template file where the parameters weren’t being passed.