Nav not showing
Closed this issue ยท 2 comments
dottd-admin commented
I've registered a nav called 'Primary', added a few items, and assigned as 'Primary' nav.
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
try Navi::build('primary')
dottd-admin commented
That was it. Thanks so much ๐