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.

Themes & Styling

Automatickly open submenu

first-time

Solved by Karmalakas View solution

Started by Radek Malík 4 years ago · 2 replies · 537 views
4 years ago

Hello, I have a little probem. On my web pages https://www.vdc-test.eu I have menu and here Servis and Kontakt is submenu. But I must on this items clicking on mouse. I want when I hover on this Items then submenu automaticly open. Can you give me answer?

TWIG
{% macro make_menu_simple_items_from_slugs_array(slugs, page) %}
    {% for slug in slugs %}
        {% set p = page.find(slug) %}
        <li>
            <a href="{{ p.url }}" class="{% if p.active or p.activeChild %}active{% endif %}">
                {{ p.menu }}
                {% if p.active %}
                    <span class="sr-only">(aktivní)</span>
                {% endif %}
            </a>
        </li>
    {% endfor %}
{% endmacro %}

{% macro make_main_menu_items(page) %}
    {% set slugs = ['/produkty', '/pronajem', '/servis', '/poptavka', '/kontakt'] %}
    {% for slug in slugs %}

        {% set p = page.find(slug) %}
        {% set childrens = p.children.visible %}

        {% if not count(childrens) %}
            <li class="{% if p.active or p.activeChild %}active{% endif %}">
                <a href="{{ p.url }}">
                    {{ p.menu }}
                    {% if p.active %}
                        <span class="sr-only">(aktivní)</span>
                    {% endif %}
                </a>
            </li>

        {% else %}
            <li class="{% if p.active or p.activeChild %}active{% endif %} dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                    {{ p.menu }}
                </a>
                <ul class="dropdown-menu dropdown-menu-{{ p.slug }} clearfix">
                    {{ _self.make_main_menu_dropdown_items(childrens, page) }}
                </ul>
            </li>

        {% endif %}

    {% endfor %}
{% endmacro %}

{% macro make_main_menu_dropdown_items(pages, page) %}
    {% for p in pages %}
        <div class="cont-20-menu" data-same-height-groupo="samecol-menu" data-same-height-min-viewport-width="768">
            <li class="dropdown-menu-top {% if p.active or p.activeChild %}active{% endif %}">
                <a href="{{ p.url }}">
                    {{ p.menu }}
                    {% if p.active %}
                        <span class="sr-only">(aktivní)</span>
                    {% endif %}
                </a>
            </li>

            {% for pp in p.children.visible %}
                <li class="{% if p.active or p.activeChild %}active{% endif %}">
                    <a href="{{ pp.url }}">
                        {{ pp.menu }}
                        {% if pp.active %}
                            <span class="sr-only">(aktivní)</span>
                        {% endif %}
                    </a>
                </li>
            {% endfor %}
        </div>
    {% endfor %}
{% endmacro %}

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 224 2 months ago
Themes & Styling · by Ian, 2 months ago
3 118 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 481 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 72 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 152 3 months ago