Search by

dorsetdigital / silverstripe-menu-manager

DorsetDigital

Reusable hierarchical menu manager for Silverstripe CMS 6

Package info

github.com/DorsetDigital/silverstripe-menu-manager

Type:silverstripe-vendormodule

pkg:composer/dorsetdigital/silverstripe-menu-manager

Statistics

Installs: 10

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-12-01 19:57 UTC

This package is auto-updated.

Last update: 2026-12-01 19:58:03 UTC


README

A flexible, hierarchical menu manager for Silverstripe CMS 6. Create and manage navigation menus independently of the page tree, with native CMS editing controls and automatic saving.

Features

  • Multiple menus — create menus for your main navigation, footer, quick links, or other site areas.
  • Nested menu items — organise links into a hierarchy, reorder them by dragging, or move items to another parent.
  • Native LinkField integration — link to pages, external URLs, email addresses, files, telephone numbers and other link types available in your project.
  • Headings — add non-clickable labels to group navigation items.
  • Automatic saving — changes are saved as you work, without a separate publish or save button.
  • Template and PHP APIs — render menus in Silverstripe templates or expose them to a headless frontend.

Requirements

  • PHP 8.3 or later
  • Silverstripe Framework 6.1+
  • Silverstripe CMS 6
  • silverstripe/linkfield 5 (installed as a Composer dependency)

Installation

Install with Composer:

composer require dorsetdigital/silverstripe-menu-manager

Run a database schema build:

vendor/bin/sake dev/build flush=1

Until a tagged beta is available, you can install the current development branch explicitly with:

composer require 'dorsetdigital/silverstripe-menu-manager:dev-main'

Managing menus

Log in as a CMS administrator and open Menus at /admin/menu-manager.

  1. Select Add menu, enter a name, and optionally set its unique menu key (for example, main or footer).
  2. Open the menu and use Add link to create items. Choose the destination with Silverstripe's LinkField.
  3. Select an item to add a child, change its type to Header only, or manage its link.
  4. Drag items to reorder them within a level. Use Move to… to move an item and its children under a different parent.

Changes save automatically. The editor shows the save status and provides a retry option if a save fails.

Menu keys

Each menu has a stable key that identifies it in your templates or application code. The key is chosen when the menu is created and stays the same if you later rename the menu.

Using menus in templates

Use the $Navigation template global with the menu key:

<nav aria-label="Footer navigation">
  <ul>
    <% loop $Navigation('footer') %>
      <li>
        <% if $Link %>
          <a href="$Link"<% if $OpenInNew %> target="_blank" rel="noopener noreferrer"<% end_if %>>$Title.XML</a>
        <% else %>
          <span>$Title.XML</span>
        <% end_if %>
        <% if $HasChildren %>
          <ul>
            <% loop $Children %>
              <li>
                <% if $Link %>
                  <a href="$Link"<% if $OpenInNew %> target="_blank" rel="noopener noreferrer"<% end_if %>>$Title.XML</a>
                <% else %>
                  <span>$Title.XML</span>
                <% end_if %>
              </li>
            <% end_loop %>
          </ul>
        <% end_if %>
      </li>
    <% end_loop %>
  </ul>
</nav>

The example renders two levels. For deeper menus, use a recursive partial.

Each navigation item exposes Title, Link, IsHeading, OpenInNew, Target, Children and HasChildren.

Using menus in PHP or a headless frontend

The NavigationService provides a read-only API:

use DorsetDigital\MenuManager\Service\NavigationService;
use SilverStripe\Core\Injector\Injector;

$navigation = Injector::inst()->get(NavigationService::class);

// Silverstripe-friendly items, with nested Children lists
$items = $navigation->getItems('main');

// Nested arrays suitable for JSON responses or static-site builds
$tree = $navigation->toArray('main');

The array representation includes id, title, link, isHeading, openInNew and children. The module does not expose a public API endpoint by default; projects can provide their own endpoint or use the service during a build.

Menus take effect as soon as they are saved in the CMS. Static frontends need to be rebuilt or refreshed separately to reflect changes.

Translations

The CMS interface supports Silverstripe's built-in internationalisation. Labels, dialogs, save feedback and validation messages use the current CMS locale; English is the fallback.

English, German and Dutch translations are included. To add another language, supply the equivalent keys in lang/<locale>.yml for PHP and client/lang/<locale>.js for the JavaScript editor. The JavaScript files use ss.i18n.addDictionary(), and the module automatically loads the relevant locale dictionary. See the Silverstripe i18n guide.

Menu names, link titles and other editor-entered content are stored as entered; translating site content is a separate concern.

Licence

BSD 3-Clause.