No Site Variables available in Partials in Partials

I dont know why, but i can’t access e.g. “$.Site” or “.Site” in my partial in another partial.
All partials are inserted with the dot at the end.

“outer” partial is like:

{{ range .Site.Params.fifty.element }} <div class="col-md-6 col-sm-12"> {{ partial "detail" . }} </div> {{ end }}

and the inner partial has no acces to any global vars.

Is anyone able to solve this riddle?

The context is changing inside the loop. The global context ., which usually contains the the information about the page and site becomes the current element over that you are ranging.

This means your are passing an element of .Site.Params.fifty.element instead of the expected . that contains meta information.

Try the following:

{{ partial "detail" $. }} # note the $ before the .

$ represents the global context, .i.e. the expected context with the meta information.

Alternatively, store the global context in a variable outside the loop:

{{ $context := . }}
{{ range .Site.Params.fifty.element }}

ok thx for that working code:
{{ partial "detail" $. }}
helped me out a lot.

second problem is:
{{ range .Site.Params.fifty.element }} {{ $slug := .slug }} <div class="col-md-6 col-sm-12"> {{ partial .partial $ . }} </div> {{ end }}

how to get access to .slug or $slug inside the partial?

I think you’ll have to use the dict func to pass several params to a partial.