Navigation registry

Table of contents

  1. Introduction
  2. Ordering and nesting entries
  3. Listing content that changes
  4. How a theme uses it
  5. Reference
  6. See also

Introduction

A feature adds its entry to the public main menu from init_feature(app). The menu is built from the features the product installs, so nobody writes it per product. Install a feature and its entry appears, remove it and the entry goes.

from splent_framework.nav.nav_registry import register_nav_item

def init_feature(app):
    register_nav_item(key="recipes", label="Recipes", href="/recipes", order=50)
How the theme composes the main menu FEATURES recipes shop collections each calls register_nav_item THE THEME Base menu get_nav_items() sorted by order Override the theme's own, if any the theme drops removed features, appends new ones Main menu on every render
The installed features make the base. The administrator's override reorders, hides, relabels and adds links on top of it, and never goes stale.

This is the menu of the public site. The sidebar and user menu of the signed-in shell have their own registry, see Menus and shells.


Ordering and nesting entries

register_nav_item(
    key="help",
    label="Help",
    href="/help",
    order=20,
    children=[
        {"label": "FAQ", "href": "/help/faq"},
        {"label": "Contact", "href": "/help/contact"},
    ],
)

Lower order comes first, and ties sort by label. The default is 100. Children open as a dropdown, and the entry stays a link that works without JavaScript. A child with "current": True is marked as current.


Listing content that changes

def _nav_children():
    service = service_proxy("CollectionsService")
    return [{"label": c.name, "href": f"/collections/{c.slug}"} for c in service.published()]

register_nav_item(key="collections", label="Collections", href="/collections",
                  order=12, children=_nav_children)

A function with no arguments runs on every render, so the dropdown follows what gets published. If it fails, or returns something that is not a list of entries, the entry renders as a plain link.


How a theme uses it

The theme reads get_nav_items() on every render. A theme with a menu editor layers the administrator’s changes on top, and the base always comes from the installed features, so the override never goes stale. For HTML in a layout slot, use a template hook.


Reference

Parameter Required Description
key yes Stable identifier. Registering it again replaces the entry
label yes Text in the menu
href yes Target URL or path
order no Sort weight, lower first. 100 by default
icon no Feather icon name, for themes that draw icons
children no A list of {"label", "href"} dicts, or a function that returns one
Function in splent_framework.nav.nav_registry Returns
get_nav_items() Every entry, sorted by (order, label)
resolve_children(item) The entry’s children as {"label", "href", "current"}. Never raises
clear_nav_items() Empties the registry, as each app does before it loads its features

Register from init_feature, never from a request handler.


See also


Back to top

splent. Distributed by an LGPL license v3. Contact us: drorganvidez@us.es