[SOLVED] HELP: Trying to output Markdown files listed in the Front Matter with .Site.GetPage

I am testing out contentful hugo tool and I set up an example app on Contentful.

Here is one of my posts from Contentful…


And I am trying to figure out how to output Markdown documents…

- 3op5VIqGZiwoe06c8IQIMO.md
- 5p9qNpTOJaCE6ykC4a8Wqg.md
- 1zwAjpe38UC8iqKMM6gu0Q.md
- 3KinTi83FecuMeiUo0qGU4.md

I tried this with Hugo, https://github.com/bzerangue/hugo-base-contentful-test/blob/master/themes/hugo-base-layouts/layouts/partials/_components/lesson-list.html

and got this…

ERROR 2018/04/29 17:52:20 Error while rendering "page" in "course/": template: /Users/bmz/Dev/contentful/exampleApp-contentful-hugo/hugo-base/themes/hugo-base-layouts/layouts/default/single.html:4:7: executing "main" at <partial "components...>: error calling partial: template: theme/partials/components/lesson-list.html:4:16: executing "theme/partials/components/lesson-list.html" at <.Site.GetPage>: can't evaluate field Site in type string

Total in 40 ms


This code gives me the error.

{{ with .Params.lessons }}
	{{ range $lesson := . }}
		{{ $p := .Site.GetPage "lesson" $lesson }}
		{{ with $p }}{{ .Title }}{{ end }}
	{{ end }}
{{ end }}

If I change .Site.GetPage to $.Site.GetPage , I get no error, but it doesn’t output anything. It should output the .Params.title that is in the lesson section markdown file.

“lesson” isn’t a kind so I don’t think you’ll have much luck there. You could use a where statement there and index or range through the results.

@budparr - thank you!

{{ with .Params.lessons }}

	{{ range $lesson := . }}

			{{ with $.Site.GetPage "page" "lesson" $lesson }}
				<li>{{ .Params.title }}</li>
			{{ end }}
	{{ end }}

{{ end }}

This works now!