How can I create a new type of page?

I am using a theme intended for blogs, but I would also like to host some informational pages too. Unlike blog posts, I would like the informational pages to have a header, sidebar and footer. I think this has to do with templates and partials, but I don’t know:

  1. How to specify that a page should use a particular template—i.e. how does Hugo determine whether a markdown file is a blog post or an informational page?
  2. What belongs in a template, and what belongs in a partial? I assume the actual header, sidebar and footer will be partials, but how does the template pull those together into an actual page?
  3. How can I pass information from the page’s front matter to a partial/template? In other words, say I want a partial that links to “previous_page”, with previous_page defined in the front matter alongside title.
1 Like

It’s up to you.

See the examples in the partial function documentation. The answer is “context”.

You might have a look at these instead:

Thank you for these links. I think they’re what I need, but I’m having some trouble getting off the ground. My info pages are in content/info and I’ve created archetypes/ too. It looks like this:

title: "{{ replace .Name "-" " " | title }}"
menu: info
weight: 1

{{- partial "info-nav.html" . -}}
{{- partial "info-nav.html" . -}}
{{- partial "info-nav.html" . -}}

layouts/partials/info-nav.html looks like this:

{{ range }}
<a href="{{ .URL }}">{{ .Name }}</a>
{{ end }}

And the front matter of my testing info page in content/info looks like this:

title: "Info Test"
type: info
    weight: 90

But still it doesn’t display three copies of the info-nav.html partial. It still looks like a default template. Where have I gone wrong, and is there a way to determine the template actually used to render the page?

It seems like you have a fundamental misunderstanding of the interaction between content, archetypes, and templates. I suggest starting with a tutorial. This video series is a little bit outdated, but still excellent in its approach and content:

When I started using Hugo, I went through this series twice, taking notes and practicing as I went along.


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.