Skip to content

Menu API

Routes are added to the sidebar navigation via the @menu_entry decorator.

Basic usage

from fastpluggy.core.menu.decorator import menu_entry

@menu_entry(label="Dashboard", icon="ti ti-dashboard")
@router.get("/dashboard", response_class=HTMLResponse)
async def dashboard(request: Request): ...

Decorator parameters

Parameter Type Default Description
label str required Text shown in the sidebar.
icon str "" Icon CSS classes, e.g. "ti ti-home" or "fas fa-chart-bar".
parent str \| None None Name of a parent item to nest under.
type str "main" Sidebar section: "main" or "admin".
position int \| None None Sort order within the parent (lower = higher).
divider_before bool False Render a separator line above this item.
divider_after bool False Render a separator line below this item.
permission str \| None None Permission string for access control (reserved).

Parent items

To group routes under a collapsible parent, create the parent in after_setup_templates and reference it by name in @menu_entry(parent=...):

# plugin.py
def after_setup_templates(self, fast_pluggy):
    fast_pluggy.menu_manager.create_parent_item(
        name="my_plugin",
        label="My Plugin",
        icon="ti ti-star",
        type="main",
        position=20,
    )

# router.py
@menu_entry(label="Overview", icon="ti ti-layout-dashboard", parent="my_plugin")
@router.get("/overview", response_class=HTMLResponse)
async def overview(request: Request): ...

@menu_entry(label="Reports", icon="ti ti-report", parent="my_plugin", position=2)
@router.get("/reports", response_class=HTMLResponse)
async def reports(request: Request): ...

Admin section

Use type="admin" to place the entry in the admin-only section (shown only to users with is_admin = True, or when auth is disabled):

@menu_entry(label="Plugin Config", icon="ti ti-adjustments", type="admin")
@router.get("/config", response_class=HTMLResponse)
async def config(request: Request): ...