Simple One Page Implementation
1. Simple One Page
Create and Display Simple _index.html page in the section containing the _content.gotmpl
_content.gotmpl
{{ .EnableAllLanguages }}
{{ $content := dict
"mediaType" "text/markdown"
"value" "Test content"
}}
{{ $page := dict
"kind" "page"
"type" "cars"
"path" "test-car"
"title" "Test Car Page"
"content" $content
}}
{{ $page | .AddPage }}
Layout
{{ define "main" }}
<h1>{{ .Title }}</h1>
<div>
{{ .Content }}
</div>
{{ end }}
2. Display a List
3. Multiple Single Pages
{{ .EnableAllLanguages }}
{{ $pages := slice
(dict "path" "car-one" "title" "Car One")
(dict "path" "car-two" "title" "Car Two")
(dict "path" "car-three" "title" "Car Three")
}}
{{ range $pages }}
{{ $content := dict
"mediaType" "text/markdown"
"value" ""
}}
{{ $page := dict
"kind" "page"
"type" "cars"
"path" .path
"title" .title
"content" $content
}}
{{ $page | $.AddPage }}
{{ end }}
4. Create Pages from and Inline JSON inside _content.tmpl
{{ .EnableAllLanguages }}
{{ $json := `
[
{
"key": "ford-f150",
"title": "Ford F-150"
},
{
"key": "toyota-corolla",
"title": "Toyota Corolla"
},
{
"key": "jeep-wrangler",
"title": "Jeep Wrangler"
}
]
` }}
{{ $cars := transform.Unmarshal $json }}
{{ range $cars }}
{{ $content := dict
"mediaType" "text/markdown"
"value" ""
}}
{{ $page := dict
"kind" "page"
"type" "cars"
"path" .key
"title" .title
"content" $content
}}
{{ $page | $.AddPage }}
{{ end }}
5. From internal Data File
{{ .EnableAllLanguages }}
{{ $brands := site.Data.vehicles.list }}
{{ range $brands }}
{{ $content := dict
"mediaType" "text/markdown"
"value" ""
}}
{{ $page := dict
"kind" "page"
"type" "cars"
"path" .key
"title" .name
"content" $content
}}
{{ $page | $.AddPage }}
{{ end }}
## 6. Front Internal Data with Params
{{ .EnableAllLanguages }}
{{ $brands := site.Data.vehicles.list }}
{{ range $brands }}
{{ $content := dict “mediaType” “text/markdown” “value” "" }}
{{ $page := dict “kind” “page” “type” “cars” “path” .key “title” .name “params” (dict “brand_key” .key “brand_name” .name “brand_image” .image “models” .models ) “content” $content }}
{{ $page | $.AddPage }}
{{ end }}