am-impact / amnav

Navigation plugin for Craft
168 stars 20 forks source link

Blind Links for Top Level #27

Closed niallthompson closed 9 years ago

niallthompson commented 9 years ago

Is it possible to have an entry in the main navigation where the top level does not link anywhere but the child items do?

I can enter a "#" for the url but just wanted to see if you had any other suggestions.

hubertprein commented 9 years ago

You could do the manual URL with a "#" like you suggested, or you could get your navigation by using the getNavRaw function. Then simply put an if statement in the macro that loops through your nodes, that'll check for the node's level.

Edited macro from readme:

{% set nav = craft.amNav.getNavRaw("yourNavigationHandle") %}

{% macro addNodeToNavigation(node) %}
    <li{% if node.active %} class="active"{% endif %}>
        <a href="{{ (node.level > 1 ? node.url : '#') }}" title="{{ node.name }}">{{ node.name }}</a>
        {% if node.children is defined %}
            <span class="navmain__more"></span>
            <div class="level{{ node.level }}">
                <span class="navmain__back">&lsaquo; Back</span>
                <ul>
                    {% for subnode in node.children %}
                        {{ _self.addNodeToNavigation(subnode) }}
                    {% endfor %}
                </ul>
            </div>
        {% endif %}
    </li>
{% endmacro %}

<nav class="navmain">
    <ul class="level0">
        {% for node in nav %}
            {{ _self.addNodeToNavigation(node) }}
        {% endfor %}
    </ul>
</nav>
niallthompson commented 9 years ago

Thanks Hubert. I'm going to go down the "#" route for now.