Freedom

Menu

·   1 min ·   Gautham Chettiar

Renders a menu for the given menu ID with support for nested items and active states.

Location : layouts/_partials/widgets/menu.html

Parameters :

ParameterTypeDescriptionDefault
menuIDstringThe menu ID from configrequired
pagePagePage contextrequired
withParentIdstringOnly render children of specified parent-
classstringAdditional CSS classes-
keystringConfig key for visibility"Menu"

Configuration :

yaml
params:
  showMenu: true  # Show/hide menu

menu:
  main:
    - name: "Home"
      url: "/"
      weight: 10
    - name: "About"
      url: "/about/"
      weight: 20
    - name: "Docs"
      url: "/docs/"
      weight: 30
      parent: "Documentation"  # For nested items

Examples :

go
// Render main menu
{{ partial "widgets/menu.html" (dict "menuID" "main" "page" .) }}

// Render only children of "Documentation"
{{ partial "widgets/menu.html" (dict "menuID" "main" "page" . "withParentId" "Documentation") }}

// With custom class
{{ partial "widgets/menu.html" (dict 
  "menuID" "main" 
  "page" . 
  "class" "custom-menu"
) }}