am-impact / amnav

Navigation plugin for Craft
168 stars 20 forks source link

Retrieve navigation block Name. #85

Closed ShaneHowell closed 7 years ago

ShaneHowell commented 7 years ago

You can get the handle using the Display navigation field type but as far as I can tell you can't get the Name/Title of the navigation element from the dropdown.

Ex:

screen shot 2016-12-21 at 1 18 49 pm

I can get the above's handle but not the Name (or Title). So all i'm able to get is diningShoppingServices but I'd like to get the title as well to display like Dining, Shopping & Services.

Is there a way to do this that i'm overlooking?

ghost commented 7 years ago

Hi Shane, Were you able to get an answer to your problem? Also, what is the use for getting the handle from the Display navigation field type? I tried to put in into {% set sidenav = craft.amNav.getNavRaw({{ entry.displayNavigationHandle}}) %} but it gives me errors whether I use quotes or not. Just trying to do a dynamically added navigation if its possible

ShaneHowell commented 7 years ago

@iamcyberio, not per-say.

If I recall correctly I ended up creating a parent and added the links as children, then I was able to pull the parent nodes props.

As for making it dynamic, this is how I achieved it:

{% set sidebar = craft.amNav.getNavRaw(entry.sidebarNavigation) %}

<section class="sidebar">
    {% for node in sidebar %}
      <h2>
        <a href="{{ node.url }}" title="{{ node.name }}">{{ node.name }}</a>
      </h2>
      <ul>
        {% for subnode in node.children %}
          <li class="{% if subnode.active %}sub-nav--active{% endif %}">
            <a href="{{ subnode.url }}" title="{{ subnode.name }}" {% if subnode.active %}class="sidebar--active"{% endif %}>{{ subnode.name }}</a>
          </li>
        {% endfor %}
      </ul>
    {% endfor %}
</section>

entry.sidebarNavigation is your field handle where you select the nav to include. In my case, it's a Display navigation field.

I'm also going to close this issue as it was never addressed here and i'm uncertain if an update was made to fix it.