Log1x / navi

A developer-friendly alternative to the WordPress NavWalker.
https://github.com/Log1x/navi
MIT License
311 stars 29 forks source link

Menu depth #48

Closed roberthallatt closed 3 years ago

roberthallatt commented 3 years ago

How would I go about displaying a menu that is 3 levels deep? I am using the sage 9 example and I can get the first two levels but not the third.

Here is my code:

    @if ($navigation->isNotEmpty())
      <ul class="my-menu">
        @foreach ($navigation->toArray() as $item)
          <li class="my-menu-item {{ $item->classes ?? '' }} {{ $item->active ? 'active' : '' }}">
            <a href="{{ $item->url }}">
              {{ $item->label }}
            </a>
            @if ($item->children)
              <ul class="my-child-menu">
                @foreach ($item->children as $child)
                  <li class="my-child-item {{ $child->classes ?? '' }} {{ $child->active ? 'active' : '' }}">
                    <a href="{{ $child->url }}">
                      {{ $child->label }}
                    </a>
                     @if ($item->children->children)
                        <ul class="my-child-menu">
                          @foreach ($item->children->children as $child)
                            <li class="my-child-item {{ $child->classes ?? '' }} {{ $child->active ? 'active' : '' }}">
                              <a href="{{ $child->url }}">
                                {{ $child->label }}
                              </a>
                            </li>
                          @endforeach
                        </ul>
                      @endif
                  </li>
                @endforeach
              </ul>
            @endif
          </li>
        @endforeach
      </ul>
    @endif
Log1x commented 3 years ago
@if ($item->children->children)

this should be

@if ($child->children)

and so on

roberthallatt commented 3 years ago

Thanks. As usual, the answer was obvious.

Sent from my iPhone

On Sep 10, 2021, at 5:21 PM, Brandon @.***> wrote:



@if ($item->children->children)

this should be

@if ($child->children)

and so on

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/Log1x/navi/issues/48#issuecomment-917219899, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABWEGY7ALEAYTY4227P3OHDUBJZHNANCNFSM5D2DN6OA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.