If you want your Hugo-powered glossary (用語集) section to have its own navigation bar or layout while keeping your codebase lean, read on! Here’s what really matters, and the “aha!” moments you need to know.
Step 1: Creating a Glossary Section
Just put your glossary Markdown files under content/en/glossary/ and content/ja/glossary/.
You don’t need anything extra for Hugo to treat them as a unique section.
Directory example:
content/
en/
glossary/
apple.md
bitcoin.md
ja/
glossary/
apple.md
bitcoin.md
Step 2: Making a Separate Globssary Navigation Partial
Want your glossary pages to have a custom menu? Just create:
layouts/partials/glossary/nav.html
Put your glossary-specific navigation HTML here.
This can be a glossary term list, an index, or whatever special menu you want.
Step 3: Using a Custom baseof.html for the Glossary
Here’s a Hugo superpower: you can use a “base template” just for the glossary section (with its own nav, etc.) by making:
textlayouts/glossary/baseof.html
Example:
<!DOCTYPE html>
<html lang="{{ .Lang }}">
<head>
{{ partial "head.html" . }}
</head>
<body>
{{ partial "glossary/nav.html" . }}
{{ block "main" . }}{{ end }}
{{ partial "footer.html" . }}
</body>
</html>
This ensures every glossary page uses your specific glossary nav and layout!
Step 4: No Need to Duplicate single.html
At first, you might think you need to copy single.html into layouts/glossary/single.html to get the layout working.
But you often don’t!
As long as your glossary content files have the correct front matter, Hugo will use your layouts/glossary/baseof.html.
Pro-tip: The main thing Hugo cares about is the “type” or the folder
- If you leave type unset, Hugo uses the section (here, “glossary”) as the type.
- So, all .md files under content/en/glossary with either:
- No type at all
- Or type = “glossary”
will automatically use layouts/glossary/baseof.html.
The Real Key: Check Your .md File Front Matter
If your glossary .md files have
type = "post"
Hugo will never use your glossary layouts, even if you made layouts/glossary/baseof.html!
Solution:
For each .md file in your glossary folders:
- Remove type (recommended for most)
- Or set type = “glossary”
That’s it! Once you do this, Hugo will apply your section-specific layouts and partials—no need to duplicate single.html or fight with conditionals.
Example Directory Structure
layouts/
glossary/
baseof.html # Glossary exclusive base layout!
partials/
nav.html # General nav
glossary/
nav.html # Glossary-exclusive nav bar!
_default/
baseof.html # Fallback for other sections
Summary
- Just putting Markdown files under content/en/glossary makes Hugo treat them separately—no extra config needed.
- Create layouts/partials/glossary/nav.html and layouts/glossary/baseof.html for custom nav/layout.
- No need to duplicate single.html!
- Always check the front matter:
Ensure glossary items do not have type = “post”. Use no type or type = “glossary”.
Remember:
Controlling Hugo’s template application is about content organization and front matter—not copying template files or writing complex conditionals!
This workflow will keep your Hugo theme simple, DRY, and powerful.
No more struggling with broken layouts or unnecessary template duplication for your custom sections. Happy Hugo theming! 🎉