In developing my second site with Hugo, the client is wanting to have several subsections on the main page that are editable. In the past, we solved this in Grav using module templates and the client would log on to the Grav admin and edit the content of each sub-module to change sub-section on the home page. Tweaks to placement could be made in the front-matter.
In Hugo, I want to do something like this in the home page:
// This is pseudo-code not functional code
{{define main}}
{{ if .Params.sub1on }}{{ .Sub1Content }}{{ end }}
{{ if .Params.sub2on }}{{ .Sub2Content }}{{ end }}
{{ .Content }}
{{ end }}
This isn’t exactly “sections”, as I currently understand them (perhaps they are?), because you wouldn’t go to /sub1content as a page at any time.
My first stab at solving this was to use local resources (.txt) pages:
And it works perfectly well. The client can commit changes to /gala.txt (in markdown) and the home page will change appropriately. And if the txt file is not found, the section is effectively turned off. This particular example is for semi-annual content that comes and goes with bespoke content each time.
But, I can’t help but wonder. Is there a “more Hugo correct” way of doing this?
I think I was editing my post while you were responding.
If your client includes links, images, or headings, and if you have created render hooks, markdownify will not fire the render hooks. The .RenderString method on .Page will.
In a leaf bundle, any file other than index.md is a resource. If it is a markdown file the .Content is fully rendered. This is better than passing a string through markdownify or .Page.RenderString because shortcodes are rendered as well.
Although this is not relevant to your current task, there are differences between a markdown file as a page resource (.Resources.GetMatch) and a markdown file as a global resource (resources.GetMatch). See this issue.
Right, but we’re not in a leaf bundle at the root index page by definition.
/
|__ _index.md
gala.txt
scholarships.txt
If I change those to markdown or html, Hugo decides they are pages and makes them addressable (which is not what I want to happen). Similarly, if I build out something like: