How do I build one markdown section into multiple pages?

I have a use case which seems really closely related to other questions here, and it seems like some of the functions of Hugo are sort of targeting what I want to do, but I’m having trouble translating the technical context to my education-based one.

What I want to be able to do is have some directories with different kinds of educational resources- activities, standards, objectives, whatever.

For the lesson for any given day, I give it a list of the different resources that are going to make up that lesson. After processing, Hugo presents the lesson plan as a single page.

In the future I want to build it out so that I can have lessons within units within courses. I know that variables within the content files aren’t processed (my first big stumbling block), and I haven’t been able to learn enough about templates and archetypes and lists to be able to figure out how to properly approach what I’m trying to achieve…

Can you point me in the direction of the proper features so I can concentrate my effort?

One approach would be to use cross references in your content. For example,

* [Activity Blah 1]({{< relref "activities/blah1.md" >}})
* [Standard Blah 2]({{< relref "standards/blah2.md" >}})
* [Objective Blah 3]({{< relref "objectives/blah3.md" >}})

That’s workable, but you end up repeating yourself a bit with the link titles.

TL;DR: The following is a dead end. The curious ones will keep reading…

I thought of another approach, but I can’t come up with a way to make it work. I’m sharing it only as a discussion starter.

That would be to use a variable in the content front matter that gets expanded in your templates (either via shortcodes or by the layout template). For example:

+++
title = "A Lesson Plan"

lesson_resources = [
  "activities/blah1.md",
  "standards/blah2.md",
  "objectives/blah3.md",
]
+++
Your content...

Then in your template, do something like this:

<ul>
{{ range $res := .Params.lesson_resources }}
  <li><a href="{{ ref $ $res }}">??</a></li>
{{ end }}
</ul>

If you needed to show the list within the page content, you could put that template into a shortcode. The problem, however, is finding a way to replace the “??” above in order to lookup the title of the referenced page.

<ul>
{{ range $res := .Params.lesson_resources }}
  <li><a href="{{ ref $ $res }}">{{ range where $.Site.Pages "Slug" "$res" }}{{ .Title }}{{ end }}</a></li>
{{ end }}
</ul>

The problem with the above attempt is that Slug won’t work. It will never point to “section/page.md”. As far as I can tell, there’s no field available on a Page that records the “content path,” nor is there a method that allows us to lookup a Page based on the “content path.”

I’ve been trying to twist things along the line of your dead end, good to see that we were both thinking in the same direction- validates my attempt somewhat!

Hugo seems like it has more features to accept dynamic content, but it still falls short of - for example- making the custom frontmatter directly available to the content page, or processing template language from within the content page, which I guess is interesting. As far as I know other static site generators don’t allow this either, it makes me curious about whether mine is just an unusual use case, or if there’s some other reason.

Your cross references technique seems like a great way for me to attack this! Thank you!