View Source Bonfire Navigation Sidebar
Overview
The Bonfire framework includes the navigation on the left sidebar, which can include pages from various extensions. Different navigation menus can be defined based on the current page (e.g., Explore and Settings pages have distinct menus).
Key Concepts
- Create new navigation menus
- Add pages to existing menus
- Override default navigation
- Use custom navigation components
Creating a New Navigation Menu
To create a new menu for your extension:
- Use the
declare_extension
macro in one of your extension views (typically the extension homepage). - Configure your extension with options like name, icon, description, and navigation menu.
declare_extension("Your Extension Name",
icon: "🎆",
description: "A short description to display in the extension settings",
default_nav: [
ExtensionName.Path.YourPageLive,
ExtensionName.Path.AnotherPageLive,
# Add more pages as needed
]
)
- For each page in
default_nav
, use thedeclare_nav_link
macro to define link properties:
declare_nav_link(l("Your Page"),
page: "your_page",
href: "/your_page",
icon: "ph:search",
icon_active: "ph:search-fill"
)
Using the Default Navigation Menu
To use the default navigation menu instead of your extension's menu:
- In each view's
mount
function, set thenav_items
property:
def mount(params, session, socket) do
{:ok,
socket
|> assign(
nav_items: Bonfire.Common.ExtensionModule.default_nav()
)
}
end
Overriding Default Navigation with a Custom Menu
To override the default navigation for specific pages:
- Create a custom navigation menu component.
- Use the
declare_nav_component("sidebar description")
macro on the custom menu. - In each view's
mount
function, set thenav_items
property:
def mount(params, session, socket) do
{:ok,
socket
|> assign(
nav_items: [ExtensionName.Path.YourPageLive.declared_nav()]
)
}
end