Skip to content
Grav 2.0 is officially stable. Read the announcement →
General

Bootstrap4 theme menu not working with onpage_menu: true

Started by pg@grav 8 years ago · 2 replies · 711 views
8 years ago

When

TXT
onpage_menu: true

is set in the frontmater of the modular.md. The mobile menu is showing up like expected so that i could navigate to the "sections". But it is not collapsing, when you click on a menu-link. It stays open. I dont know if this is a bug.
I think the part that handle this is in the modular.twig.html

TWIG
...
{% set show_onpage_menu = header.onpage_menu == true or header.onpage_menu is null %}
...

{% block javascripts %}
    {% if show_onpage_menu %}
        {% do assets.add('theme://js/singlePageNav.min.js') %}
    {% endif %}
    {{ parent() }}
{% endblock %}

{% block bottom %}
    {{ parent() }}
    {% if show_onpage_menu %}
        <script>
        // singlePageNav initialization & configuration
        $('.navbar-nav').singlePageNav({
            //offset: $('#header').outerHeight(),
            filter: ':not(.external)',
            updateHash: true,
            currentClass: 'active'
        });
        </script>
    {% endif %}
{% endblock %}
...

Can somebody give me a hint how i can solve this
Thank pgrav

8 years ago

On solution with JS is,
$('.navbar-nav>li>a').on('click', function(){
$('.navbar-collapse').collapse('hide');
});
although there is probably a better way?
pgrav

8 years ago

@pgrav This is an issue with Bootstrap itself, which of course is carried over into theme Bootstrap4.

I don't know of a better way. I've only found solutions which are similar/equal to yours.

It might be an idea to open an issue at the repo of this theme and ask if they could implement the solution. Or maybe create a pull request...

last edited 09/01/18 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
General · by jean-louis67, 3 days ago
2 81 2 days ago
General · by Andy Miller, 7 days ago
0 146 7 days ago
General · by Veehem, 1 week ago
0 146 1 week ago
General · by milkboy, 1 week ago
0 139 1 week ago
General · by ian russell, 2 weeks ago
2 226 2 weeks ago