navi: Undefined variable

Hi Brandon,

I’ve just installed latest Sage 10 release, and attempting to add back in various navs.

Unfortunately, I’m getting a weird ‘Undefined variable’ error:

Heres what I have stripped back to just one nav:

Composers > Navigation.php:

<?php

namespace App\View\Composers;

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

class Navigation extends Composer
{
    /**
     * @var array
     */
    protected static $views = [
        'partials.header.nav.upper',
    ];

    /**
     * @return array
     */
    public function with()
    {
        return [
            'upper' => $this->upper(),
        ];
    }

    /**
     * @return array
     */
    public function upper()
    {
        if (Navi::build()->isEmpty()) {
            return;
        }

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

then in header.blade.php:

        @if ($upper)
          SHOW ME THIS TEXT IF WORKING CORRECTLY
        @endif

I’ve tested the same setup on an older version of Sage 10 and it works as expected.

Any idea why this may be happening on newest release (but I could be doing something stupid 🙈)?

Here is error screen attached.

Thanks

Screenshot 2021-04-02 at 01 20 00

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

looking into it – not entirely sure what’s happening but seems to be an issue with Acorn perhaps. could you try wp acorn optimize:clear (or yarn clean) after changing everything?

Yeah, that was it Brandon. I should’ve have spotted that 🙈. Many thanks 👍

so it looks like it’d be partials.header.header in your current error screenshot? unless you use $upper inside of upper.blade.php and then @include it in your header.