Partial context and parameter

Hi!

I have a template in layouts/partials/folder/test.html , in which I read. some json data like so:

{{ $data := index $.Site.Data.mydata $.Site.Language.Lang }}

I want call this template from a shortcode like so:

{{ partial 'folder/test . }}

this works. Now I want to add some additional parameters, so I wrapped the stuff into a dict

{{ partial 'folder/test (dict "context" . "my_type" "my test") }}

And didn’t get the data anymore. This is what I tried in the partial:

{{ $data := index $.Site.Data.mydata $.Site.Language.Lang }} -> dies silent, throws no error 
{{ $data := index .context.Site.Data.mydata $.Site.Language.Lang }}

With the 2nd. one I get this error:

execute of template failed at <index .context.Site.Data.mydata $.Site.Language.Lang>: error calling index: index of type map[string]interface {} with args [<nil>] failed: value is nil; should be of type string

Why can’t I get to the context like this?

What’s my problem here?
What means $. in this case?

Best regards carsten

When working with a Site object use the global site function instead.

1 Like