$.Site.Pages is nil inside a data partial

I have a partial that is called like this:

{{ partial "a.html" $.Site.Data.something.somethingelse }}

Inside that partial, $.Site.Pages is nil (so is .Site.Pages). Isn’t it possible to have access to all pages in a context like this?

As per the documentation

All partials are called within your templates using the following pattern:

{{ partial "<PATH>/<PARTIAL>.html" . }}

In the pattern above, note how “the dot” ( . ) is required as the second argument to give the partial context.

More on the dot: over here

I don’t quite understand what you are trying to achieve, since that is not the syntax typically used to call a set of data files. BTW .Site.Data is used in templates to call files that reside under a project’s /data/ folder: see Data Templates

I do not see $.Site.Pages in {{ partial "a.html" $.Site.Data.something.somethingelse }}

You need to share your project’s source code and offer a description about what you are trying to render through said partial.

For example, I have a data file like this:

data/category-a/sub-category-3/item42.yaml

I run the following to create a block of content based on that:

{{ partial "show-item.html" $.Site.Data.category-a.sub-category-3.item42 }}

This has been working fine for me. However, now I need to add something extra to this block of content, and its information comes from a page (with a certain relationship to the data file) rather than the data file itself, but it seems like I can’t access pages with .Site.Pages or .GetPage (or .GetPage) inside this partial.

For what you mentioned about the dot, I’d have to use a dict to pass both the dot and the data file to the partial, which makes my templates a little messy and I prefer to avoid it if I can. I was hoping that the existing input could give the partial enough context to access “$”, or that there’s another simple way of doing it.

you could try site global function, it’s undocumented feature.

access via .Site variable

{{ .Site.GetPage ... }}}

access via site function

{{ site.GetPage ... }}}
1 Like

Thanks! That solved the problem.

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