Passing a data object to a partial?

I’ve looked at the partial dock and cant figure this out.

I’m looping through my content files and need to pass some variables, I’d like to pass an object specifically a map that’s generated from my json, I tried (dict x x) and that didn’t work I could only get single values, I need to pass multiple of these “Title data” “Subtitle data” all from my json here’s an example of the subtitle:
{{ $page_data.list_page.subtitle }}

And here’s the object:
myData.json:

            "list_page": {
                "single_page_link_enabled": true,
                "subtitle": {
                    "enabled": true, 
                    "uppercase_enabled": true,
                    "font_typeface": "",
                    "font_color": "black",
                    "font_size": 1,
                    "text_align": "left"
                },

How can I pass that to my partial?

data/myData.json

{
  "list_page": {
    "single_page_link_enabled": true,
    "subtitle": {
        "enabled": true,
        "uppercase_enabled": true,
        "font_typeface": "",
        "font_color": "black",
        "font_size": 1,
        "text_align": "left"
    }
  }
}

layouts/_default/single.html

{{ define "main" }}
  <h1>{{ .Title }}</h1>
  {{ .Content }}
  {{ $json := .Site.Data.myData }}
  {{ partial "foo.html" (dict "ctx" . "json" $json) }}
{{ end }}

layouts/partials/foo.html

{{ $ctx := .ctx }}
{{ $json := .json }}

{{ $json.list_page.subtitle.font_color }}
2 Likes

My hero.

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