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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Bootstrap4 theme menu not working with onpage_menu: true

Started by pg@grav 8 years ago · 2 replies · 640 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 Jerry Hunt, 4 days ago
2 82 12 hours ago
General · by pamtbaau, 17 hours ago
1 55 16 hours ago
General · by Andy Miller, 1 day ago
0 45 1 day ago
General · by Marcel, 12 months ago
6 348 5 days ago
General · by Duc , 5 days ago
3 43 5 days ago