Hi Hugo folks,
I wanted to raise this question here as I am pretty confused. I am using the below content adapter which recursively parses over a JSON file & adds pages and sections. This template works great for my needs but I am trying to reuse it across different parts of my site.
In my case I am trying to pull different projects & content into different parts of the site.
That is where you can see I have added a conditional to check if the project id is in the JSON & will continue to the add page to add content. I have also added the project id to all levels of the hierarchy including the ‘children’ pages and so on.
The issue I am experiencing is when I add this content adapter to another part of the site- it seems like the initial one is overwritten.
For clarity say I have 2 folders: test 1 & test 2. I have pasted the same content adapter into both of these directories with the only difference being the index files and the project id in the conditional of the go template.
Would anyone have any ideas as to why this may be happening? If more detail is required I can boot up a Github repo to reproduce the issue.
{{ $jsonContent := site.Data.nested_data }}
{{ with $jsonContent }}
{{ template "walk" (dict "data" .roots "path" "" "ctx" $) }}
{{ end }}
{{ define "walk" }}
{{ range .data }}
<!-- Build the path for the current node -->
{{ $urlLink := .title | urlize }}
{{ $path := path.Join $.path .hugoPath }}
<!-- Render the page content -->
{{ template "add-page" (dict "data" . "path" $path "ctx" $.ctx) }}
<!-- Recursively walk through children -->
{{ with .children }}
{{ template "walk" (dict "data" . "path" $path "ctx" $.ctx) }}
{{ end }}
{{ end }}
{{ end }}
{{ define "add-page" }}
{{ with .data }}
{{/* Define the list of project IDs to include */}}
{{ $includedProjects := slice "123456" }}
{{if in $includedProjects .project_id}}
<!-- Recursively walk through children -->
{{ $taxonomies := readFile "config/_default/taxonomies.toml" | transform.Unmarshal }}
{{ $params := dict }}
{{ range $key, $value := . }}
{{ if isset $taxonomies $key }}
{{ $taxonomy := index $taxonomies $key }}
{{ $params = merge $params (dict $taxonomy $value) }}
{{ else }}
{{ $params = merge $params (dict $key $value) }}
{{ end }}
{{ end }}
{{ $content := dict "mediaType" "text/html" "value" .content }}
{{$kind := ""}}
{{$type := ""}}
{{ if .children}}
{{ $kind = "section" }}
{{ $type = "tileView"}}
{{ else }}
{{ $kind = "page" }}
{{ $type = "docs"}}
{{ end }}
{{ $page := dict
"content" $content
"kind" $kind
"params" $params
"path" $.path
"title" .title
"type" $type
"description" .description
"tabletype" .tableType
}}
{{ $.ctx.AddPage $page }}
{{ end }}
{{ end }}
{{ end }}
Any help would be… helpful! Thanks in advance.