Undefined variable
fabianwurk opened this issue ยท 19 comments
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
Should your $views
be set to just partials.header
?
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.
Yeah, that was it Brandon. I should've have spotted that
Sorry, back again
protected static $views = [
'partials.header.header',
];
or
protected static $views = [
'partials.header.header.nav',
];
Here is current file structure ...
I've tried many other combinations but all throwing various errors each time.
Any suggestions on where it could be going wrong?
Thanks
Repo here if it helps for referencing:
so it should be $views = ['partials.header.nav.upper']
I think?
that means its working. your menu is just empty. theres a PR open to fix this from throwing an exception
Repo updated for ref: https://github.com/fabianwurk/atomic-jit
@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.
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?
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.
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.
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?
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
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
(oryarn clean
) after changing everything?
This fixed my very similar issue! YAY.