Log1x / navi

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

Nav not showing #23

Closed dottd-admin closed 4 years ago

dottd-admin commented 4 years ago

I've registered a nav called 'Primary', added a few items, and assigned as 'Primary' nav.

Screenshot 2020-09-09 at 18 07 13

then in setup:

    register_nav_menus([
        'primary' => __('Primary', 'sage'),
    ]);

and in Composers > Navigation:

<?php

namespace App\View\Composers;

use Roots\Acorn\View\Composer;
use Log1x\Navi\Facades\Navi;

class Navigation extends Composer
{
    /**
     * List of views served by this composer.
     *
     * @var array
     */
    protected static $views = [
        'partials.header.nav.primary',
    ];

    /**
     * Data to be passed to view before rendering.
     *
     * @return array
     */
    public function with()
    {
        return [
            'primary' => $this->navigation(),
        ];
    }

    /**
     * Returns the primary navigation.
     *
     * @return array
     */
    public function navigation()
    {
        if (Navi::build()->isEmpty()) {
            return;
        }

        return Navi::build()->toArray();
    }
}

then in my views:

@if ($primary)
<ul 
  class="inline-block relative"
  x-data="{ open: false }"
  @click.away="open = false"
>
  @foreach ($primary as $item)
    <li class="inline-block {{ $item->classes ?? '' }} {{ $item->active ? '' : '' }}">
      <a href="{{ $item->url }}" {!! $item->children ? '@click="open = !open"' : '' !!} class="focus:outline-none cursor-pointer inline-block hover:text-g-dg flex px-3 py-3 text-pcol">
        {{ $item->label }}
      </a>
    </li>
  @endforeach
</ul>
@endif

But menu not displaying.

And even if I just have the following, nothing displays:

@if ($primary)
<h1>test</h1>
@endif

I'm using Sage 10.

Any idea what may be wrong?

Thanks.

Log1x commented 4 years ago

try Navi::build('primary')

dottd-admin commented 4 years ago

That was it. Thanks so much 👍