Render Nested JSON Array into a YAML template

Currently I am working with Regi’s Pages from Remote repository and I am unable to figure out how I can render a Nested JSON array as YAML front matter.

JSON input:

  "data": {
    "details": {
      "description_highlight_bullet_points": [
        "Weight 315 gr",
        "Length 28 cm",
        "Circumference 99 cm",
        "Pouch with zipper",
        "Fabric 100% Polyester​"

I am using this YAML template that resides under assets.

Ideally the above array should be called conditionally because not every file in the data set contains it.

But I just cannot figure it out.

On a plain template I am able to render the array with something like:

{{ with .data }}
{{ with .details.description_highlight_bullet_points }} 
  {{ range $key, $value := . -}}
  {{ $key := (print "-" $value) "\n" }}{{ end }}{{ end }}
{{ end }}

But I cannot pass it into the YAML template without duplicating the call to the remote JSON.

Also I have looked into using both Scratch and/or the index to pass the array into the dictionary of the partial that calls the YAML template to no avail.

What does the code around your code sample look like? It might just be some form of := vs = confusion somewhere?

It was indeed a context issue. Also it was very late and I was tired.

1 Like

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