Subnavigation
In ShipWithDjango, the subnavigation menu that users see when logged into the platform is fully customizable through a configuration file, eliminating the need to modify template files directly. This approach provides a flexible and centralized way to manage the navigation structure across your application.
The subnavigation configuration is defined in the CONFIG/subnavigation.py
file. This file outlines the different sections and items that will appear in the user's subnavigation menu, allowing you to control what options are available based on the user's role or other conditions.
Example Subnavigation Configuration
Here’s a breakdown of how the example subnavigation configuration is structured:
Structure and Components
Subnavigation Sections:
The
GLOBAL_SUBNAV
list contains dictionaries, each representing a section in the subnavigation menu.Each section has a
key
,name
, and other properties likeshow_title
(controls if the section title is displayed) andis_active
(determines if the section is active and visible).
Menu Items:
Each section contains an
items
list, which holds individual menu items.Each item is defined by a
key
,name
,url_name
(the named URL pattern for the link),icon
(the icon displayed next to the item), andis_active
.Some items, like the "Adminpanel," can have additional properties such as
superuser_required
, which restricts access to superusers.
Customizing the Subnavigation
To customize the subnavigation for your application:
Add or Modify Sections:
You can add new sections or modify existing ones by editing the
GLOBAL_SUBNAV
list. Define new sections with uniquekey
values and populate them with relevantitems
.
Customize Menu Items:
Within each section, you can customize the menu items by changing their
name
,url_name
, andicon
. You can also control their visibility withis_active
or restrict access to certain roles, like superusers, using additional flags.
Dynamic Subnavigation:
Utilize conditional logic to dynamically include subnavigation sections based on the presence of specific apps or conditions within your project.
Last updated