0

I'm a new Craft user and a fairly new web developer.

I have the following code:

<ul class="flex flex-col items-end mb-4 text-right md:mb-0 md:flex-row md:space-x-4 md:items-center lg:space-x-8 2xl:space-x-12 md:hidden">
    {% for link in links %}
        <li class="py-2 text-sm font-bold md:font-normal md:text-xs lg:text-sm xl:text-base 2xl:text-lg">
            {% if link.internLink is not defined and link.externalLink == '' and link.customLink == '' and link.button == '' %}
                <span>{{ link.title }}</span>
            {% endif %}
            {# Check for entry type / get related entry #}
            {% if link.internLink.one() %}
                {% set intern = link.internLink.one() %}
                <a href="{{ intern.url }}" class="hover:underline {{ _m.is_active(intern.slug) }}">{{ link.title }}</a>
            {% elseif link.customLink != '' %}
                <a href="{{ link.customLink }}" class="hover:underline {{ _m.is_active(link.customLink) }}">{{ link.title }}</a>
            {% elseif link.externalLink != '' %}
                <a target="_blank" href="{{ link.externalLink }}" class="hover:underline {{ link.externalLink == craft.app.request.url ? activeClass : '' }}">{{ link.title }}</a>
            {% elseif link.button != '' %}
                <a href="{{ link.button }}" class="btn blue outline">{{ link.title }}</a>
            {% endif %}

            {% if link.hasDescendants() %}
                {% for children in link.children %}
                    <p>{{ children.title }}</p>
                {% endfor %}
            {% endif %}
            {% for children in link.getDescendants().all() %}
        <p>{{ children.title }}</p>
    {% endfor %}
        </li>
    {% endfor %}
</ul>

It's a nested menu, that contains another submenu (so there are 3 levels if you will). Everything loops out and is shown correctly. But I want to be able to toggle the menus by clicking the heading.

To clarify: by clicking on "my menu" the "sub menus" should appear. By then clicking on the sub menu, the "sub menu to the submenus" should appear. Not all submenus will have their own submenus. The logic is there but I don't know how to make it togglable.

Thanks in advance!

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.