Header Menus

Complete guide to configuring and managing navigation menus in HBStack framework, including main menus, submenus, and section-based navigation.

This comprehensive guide explains how the HBStack framework handles navigation menus in Hugo. Learn how to configure main menus, create submenus, manage section-based navigation, and customize menu appearance with icons and descriptions. The guide covers both automatic menu generation from content structure and manual menu configuration using YAML files.


How HBStack Framework Handles Menus

The HBStack framework provides a flexible menu system that combines Hugo’s built-in menu functionality with enhanced features for navigation management.

There is a file located in the config/_default/ folder named menus.en.yaml. Since only English is used in this setup, it can be renamed to menus.yaml for simplicity.

Understanding Menu Sources

Before examining the configuration file, it’s important to understand where the main menus originate:

  • Automatic Generation: Main menus are generated directly by Hugo as part of content sections
  • Content Structure: Everything under the content directory is considered a section, either as a leaf bundle or branch bundle
  • Navigation Bar: The main navigation contains Docs, Gallery, Examples, and Blog menus
  • Index Files: These menus appear because their respective folders contain _index.md files with explicit menu entries

Docs Menu

The Docs menu is generated from its root folder and displays the sidebar with all containing folders when present.

 1# content/docs/_index.md
 2---
 3title: Docs
 4menu:
 5  main:
 6    weight: 1
 7    params:
 8      icon:
 9        vendor: bs
10        name: book
11---

Important Notes:

  • If these entries are missing, the docs sidebar will not appear
  • The docs layout is handled by its dedicated module
  • Docs content automatically appears in the sidebar
  • The Docs menu can serve as a parent for other folders, allowing the same docs structure for different topics

Blog Menu

The Blog menu demonstrates the standard menu configuration pattern:

 1# content/blog/_index.md
 2---
 3title: Blog
 4menu:
 5  main:
 6    identifier: blog
 7    weight: 4
 8    params:
 9      icon:
10        vendor: fas
11        name: blog
12---

Key Properties:

  • Title: Sets the menu title to “Blog” (can be overridden with the name parameter)
  • Parent: Has no parent, belongs directly to the main menu
  • Identifier: The blog identifier represents the blog folder and is used for referencing
  • Main Menu: The main parameter is Hugo’s built-in field for the primary navigation

Note: The folder name doesn’t matter for menu display. It’s referenced by the name parameter if present, otherwise by the title. The identifier is used for internal referencing.

Blog Submenus

The Blog menu displays five submenus that come from other sections under the content folder: archives, authors, categories, series, and tags. Each has an _index.md file with entries like:

 1# content/archives/_index.md
 2---
 3title: Archives
 4menu:
 5  main:
 6    parent: blog
 7    params:
 8      icon:
 9        vendor: bs
10        name: archive
11        className: text-primary-emphasis
12      description: Posts archive.
13---

To make the archives folder appear under blog, the blog identifier is set as the parent property. This pattern applies to all other blog-related folders.

Root Content Menu

The root content/_index.md file manages the home page menu:

 1# content/_index.md
 2---
 3title: HB Theme Template
 4menu:
 5  main:
 6    name: Home
 7    weight: 1
 8    params:
 9      icon:
10        vendor: bs
11        name: house
12---
13# Note: Content here is not rendered as it's in the root _index.md file

Behavior:

  • If present, creates a “Home” main menu item
  • If commented out, the menu won’t appear
  • The name field overrides the title for display purposes
  • Icons are defined under params/icon with vendor-specific syntax

Custom Menus in Configuration

Creating External Menus

For menus that aren’t part of your content sections (like external links), use the menus.yaml file:

 1# config/_default/menus.yaml
 2main:
 3  - name: Support
 4    weight: 100
 5    url: https://github.com/hbstack
 6    params:
 7      description: The HB support community.
 8      icon:
 9        vendor: font-awesome-solid
10        name: headset

Adding New Custom Menus

Add new menus using the same format:

 1main:
 2  - name: New Menu
 3    identifier: new-menu
 4    weight: 200
 5    url: https://github.com/example/
 6    params:
 7      header: Description for the new menu.
 8      icon:
 9        vendor: font-awesome-solid
10        name: headset

Creating Submenus

Add submenus using the parent field with the parent’s identifier:

 1main:
 2  - name: Support
 3    identifier: support
 4    weight: 100
 5    url: https://github.com/hbstack
 6    params:
 7      header: The HB support community.
 8      icon:
 9        vendor: font-awesome-solid
10        name: headset
11
12  - name: Documentation
13    parent: support # References the 'support' identifier
14    url: https://hbstack.dev/
15    weight: 1
16    params:
17      icon:
18        vendor: bs
19        name: book
20        className: text-primary
21      description: The documentation.

Important: The parent field uses the identifier value, not the display name.

Content-Based Submenus

Create content-based submenus by adding a new section folder:

 1# content/posts/_index.md
 2---
 3title: My Posts
 4menu:
 5  main:
 6    parent: blog
 7    identifier: posts
 8    name: Posts # Display name
 9    weight: 1
10    params:
11      icon:
12        vendor: bs
13        name: archive
14        className: text-primary-emphasis
15      description: Personal posts
16---

For nested organization, create subsections:

 1# content/posts/hugo/_index.md
 2---
 3title: Hugo
 4menu:
 5  main:
 6    parent: posts # References the posts identifier
 7    weight: 1
 8    params:
 9      icon:
10        vendor: bs
11        name: archive
12        className: text-primary-emphasis
13      description: About Hugo
14---

Page-Level Configuration

Individual Page Front Matter

Pages within sections don’t need menu entries as they’re managed by their parent bundle:

1---
2date: 2023-10-05T22:40:23+07:00
3title: Hugo Basics
4series:
5  - hugo
6tags:
7  - Static Site Generator
8---

Cross-Menu Appearances

Any page can appear in multiple menus by adding additional menu configurations:

 1---
 2title: 'Introduction'
 3description: |
 4  HB (Hugo Bootstrap) is a modular framework built on top of Hugo and Bootstrap v5.3.0+.
 5  HB is not a theme, it's used to build themes.
 6date: 2022-12-14T19:53:42+08:00
 7draft: false
 8nav_weight: 1
 9series:
10  - Docs
11tags:
12  - Introduction
13authors:
14  - HB
15menu:
16  footer: # Additional menu placement
17    parent: docs
18    weight: 31
19    params:
20      icon:
21        vendor: fas
22        name: hands-clapping
23---

This configuration makes the same page appear in both the main docs section and the footer menu.

Best Practices

  1. Consistent Identifiers: Use clear, consistent identifiers for menu items
  2. Logical Weights: Use weight values that allow for easy insertion of new items
  3. Icon Consistency: Stick to one or two icon vendors for visual consistency
  4. Descriptive Names: Use clear, descriptive names for menu items
  5. Bundle Management: Properly manage content bundles with _index.md files