Generic data approach?

I’m trying to use a generic way to pull my data from my templates, I have my json object that contains the page data I want to pull.

pages.json:

{
    "page_1": {
        "foo": ""
    }
}

I’d like to be able to pull this data by using string concatenation like so:

Pseudo code would look like:
$site_data.{{ .Title }}.foo
in this case .Title = “page_1”

How can I achieve this?

I believe the index function is what you’re looking for.

{{ index .Site.Data .Title "foo" }}
1 Like

Thank you for the quick reponse that was exactly it!

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