I have a Drupal 8 site and them (upgraded from Drupal 7) and the main menu collapses to a button when the page is narrow enough (i.e. on a mobile device). Or at least it is supposed to. I did not design the theme.
SITUATION
Unfortunately when the menu is collapsed into a button, clicking on the button does NOT open the menu.
SITE SETUP
It seems that the old theme used jQuery to handle the collapse of the menu.
I have installed the jquery_ui module.
I added jquery to the .libraries.yml file
dependencies:
- core/jquery
- core/jquery.ui
- core/jquery.once
There are 4 template files which the only reason I can see is so that the main menu (which is hardcoded) can style the active menu item for the page.
- page--node--2.html.twig
- page--node--3.html.twig
- page--node--6.html.twig
- page.html.twig
Each of those pages has as the last line of the page a reference to the JavaScript file located in the site as
<script src="sites/all/themes/custom/mytheme/js/main.js"></script>
FIXED SOME OF IT
Adding jquery.main.js to the /js directory and adding the reference to it in the .library.yml file as
js:
js/main.js: {}
js/jquery.main.js: {}
was enough to get all of the pages to collapse and open the menu EXCEPT THE FRONT PAGE.
JURY-RIG
I can get the front page menu to work if I add a reference to the bottom of the page to the jquery.main.js file I manually added to the local /js directory.
<script src="sites/all/themes/custom/mytheme/js/main.js"></script>
But then the other pages (not node 2, 3 or 6) which should use page.html.twig are run, it does NOT un-collapse the menu.
So for now I make a page--front.html.twig file which includes BOTH script referecnes to the JavaScript files, and all other pages have just the one (to main.js).
QUESTION I have a couple:
- What is the more standard way to situate this? I don't imagine that having a local jquery.main.js file is the best solution but it wasn't working with out it.
- Why would the front page not operate like the other pages in accessing the JavaScript and jQuery?
Thank you for any insight.