Installing wagtailmenus¶
Install the package using pip:
pip install wagtailmenus
Add
wagtailmenus
andwagtail.contrib.modeladmin
to theINSTALLED_APPS
setting in your project settings:INSTALLED_APPS = [ ... 'wagtail.contrib.modeladmin', # Don't repeat if it's there already 'wagtailmenus', ]
Add
wagtailmenus.context_processors.wagtailmenus
to thecontext_processors
list in yourTEMPLATES
setting. The setting should look something like this:TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', ' DIRS': [ os.path.join(PROJECT_ROOT, 'templates'), ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.debug', 'django.template.context_processors.i18n', 'django.template.context_processors.media', 'django.template.context_processors.request', 'django.template.context_processors.static', 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'wagtail.contrib.settings.context_processors.settings', 'wagtailmenus.context_processors.wagtailmenus', ], }, }, ]
Run migrations to create database tables for wagtailmenus:
python manage.py migrate wagtailmenus
This step is optional. If you’re adding wagtailmenus to an existing project, and the tree for each site follows a structure similar to the example below, you may find it useful to run the ‘autopopulate_main_menus’ command to populate main menus for your site(s).
However, this will only yield useful results if the ‘root page’ you’ve set for your site(s) is what you consider to be the ‘Home’ page, and the pages directly below that are the pages you’d like to link to in your main menu.
For example, if your page structure looked like the following:
Home (Set as 'root page' for the site) ├── About us ├── What we do ├── Careers | ├── Vacancy one | └── Vacancy two ├── News & events | ├── News | └── Events └── Contact us
Running the command from the console:
python manage.py autopopulate_main_menus
Would create a main menu with the following items:
- About us
- What we do
- Careers
- News & events
- Contact us
If you’d like wagtailmenus to also include a link to the ‘home page’, you can use the ‘–add-home-links’ option, like so:
python manage.py autopopulate_main_menus --add-home-links=True
This would create a main menu with the following items:
- Home
- About us
- What we do
- Careers
- News & events
- Contact us
Note
The ‘autopopulate_main_menus’ command is meant as ‘run once’ command to help you get started, and will only affect menus that do not already have any menu items defined. Running it more than once won’t have any effect, even if you make changes to your page tree before running it again.
Installing wagtail-condensedinlinepanel
¶
Although doing so is entirely optional, for an all-round better menu editing experience, we recommend using wagtailmenus together with wagtail-condensedinlinepanel (version 0.3
or above).
wagtail-condensedinlinepanel
offers a React-powered alternative to Wagtail’s built-in InlinePanel
with some great extra features that make it perfect for managing menu items; including drag-and-drop reordering and the ability to add new items at any position.
If you’d like to give it a try, follow the installation instructions below, and wagtailmenus will automatically use the app’s CollapsedInlinePanel
class.
Install the package using pip:
pip install wagtail-condensedinlinepanel>=0.4
Add
condensedinlinepanel
to theINSTALLED_APPS
setting in your project settings:INSTALLED_APPS = [ ... 'condensedinlinepanel', ... ]
Note
If for some reason you want to use wagtail-condensedinlinepanel
for
other things, but would prefer NOT to use it for editing menus, you can
make wagtailmenus revert to using standard InlinePanel
by adding
WAGTAILMENUS_USE_CONDENSEDINLINEPANEL = False
to your project settings.