Log1x / navi

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

Undefined variable #38

Closed fabianwurk closed 3 years ago

fabianwurk commented 3 years ago

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

Log1x commented 3 years ago

Should your $views be set to just partials.header ?

fabianwurk commented 3 years ago

Have added an extra folder level to segment and manage the partials a bit easier .......

Screenshot 2021-04-02 at 01 37 19
Log1x commented 3 years ago

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.

fabianwurk commented 3 years ago

Yeah, that was it Brandon. I should've have spotted that πŸ™ˆ. Many thanks πŸ‘

fabianwurk commented 3 years ago

Sorry, back again πŸ™ˆ .... I had went and set up all the navs, and I needed to change theme name for repo. When I went back in and restested all, I'm getting errors as per attached depending if I use:

    protected static $views = [
        'partials.header.header',
    ];

Screenshot 2021-04-05 at 00 50 21

or

    protected static $views = [
        'partials.header.header.nav',
    ];

Screenshot 2021-04-05 at 00 53 39

Here is current file structure ...

Screenshot 2021-04-05 at 00 49 41

I've tried many other combinations but all throwing various errors each time.

Any suggestions on where it could be going wrong?

Thanks

fabianwurk commented 3 years ago

Repo here if it helps for referencing:

https://github.com/fabianwurk/atomic-jit

Log1x commented 3 years ago

so it should be $views = ['partials.header.nav.upper'] I think?

fabianwurk commented 3 years ago

Yeah, had actually tried that too earlier but no joy ... Screenshot 2021-04-05 at 02 21 20

Log1x commented 3 years ago

that means its working. your menu is just empty. theres a PR open to fix this from throwing an exception

fabianwurk commented 3 years ago

Sorry, confused on this.

Screenshot 2021-04-05 at 15 10 20

The nav is assigned ....

Screenshot 2021-04-05 at 15 00 50

but even if I try var dumping the array it just returns error ....

Screenshot 2021-04-05 at 15 08 54
fabianwurk commented 3 years ago

I've also changed the file from the PR. It does sort the error, but it's still returning null from var dump of array ...

Screenshot 2021-04-05 at 15 18 27

fabianwurk commented 3 years ago

Repo updated for ref: https://github.com/fabianwurk/atomic-jit

fabianwurk commented 3 years ago

@Log1x I've now tested so many configurations of this, and still not working. Also tested this on bare bones fresh install of latest Sage 10 repo. Seems to be an issue where if you change the name of the nav, or add any additional navs, it then fails to show nav. Can you please test this your side to see if you are experiencing same issue? Thanks.

https://github.com/fabianwurk/atomic-jit

Log1x commented 3 years ago

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?

fabianwurk commented 3 years ago

I tried wp acorn optimize:clear, but no difference unfortunately. FYI ... Works fine with earlier sage 10 branch as I've tested same setup on it so must be some issue with that latest version.

Log1x commented 3 years ago

unfortunately I wasn't who did a bulk of the changes in the current master of acorn right now and I've been a little swamped with work – so I'm not entirely sure what got broke and where yet. I know it's not a problem with Navi in particular though but Composers as a whole.

Log1x commented 3 years ago

your config/view.php or whatever is up to date with the latest master branch of Sage 10? try enabling globals in config/app.php and see if that makes a difference?

fabianwurk commented 3 years ago

Yeah no worries at all. Not a major issue as happy to use earlier version of Sage 10 without Tailwind JIT. Thanks for taking a look anywayπŸ‘

minemindmedia commented 1 year ago

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?

This fixed my very similar issue! YAY.