Installing wagtailmenus¶
Install packages using pip:
pip install wagtailmenusAdd
wagtailmenusto theINSTALLED_APPSsetting in your project settings:e.g. settings/base.py¶INSTALLED_APPS = [ ... 'wagtailmenus', ]
Add
wagtailmenus.context_processors.wagtailmenusto thecontext_processorslist in yourTEMPLATESsetting. The setting should look something like this:e.g. settings/base.py¶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 wagtailmenusThis 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_menusWould 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-linksThis 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.