Access $.Site.Data from partial

I’m trying to access a json file in the data folder. It is accessible from _default templates but I cannot get to it with exact same code in a partial that is passed custom arguments. Example code:

{{ with $.Site.Data.MediaX }}
{{warnf "_DEFAULT:LIST:: Media query for 'X': %q" (index $.Site.Data.MediaQuery "XX" ) }}
{{ index $.Site.Data.MediaQuery "XX" }}
{{ else }}
{{ errorf " media query json file not found in data folder." }}
{{ end }}

Is $.Site variable accessible from partials that do not get passed the global context?

smart hint is there

Get the Site object from a partial

All the methods below, e.g. .Site.RegularPages can also be reached via the global site function, e.g. site.RegularPages , which can be handy in partials where the Page object isn’t easily available.

use the global variable site instead page attribute .Site

1 Like

gah! I’m humbled. Speed reading results in wasted time.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.