Log1x/navi

Sage 9 Integration

fabianwurk opened this issue · 8 comments

Probably dumb question, I have this working with Sage 10, just wondered what I need to do to get it working with Sage 9. On the docs it shows:

`use Log1x\Navi\Navi;

$navigation = (new Navi())->build('primary_navigation');`

Just wondering where this goes?

Thanks

Log1x commented

A controller should suffice.

Just return (new Navi())->build('primary_navigation'); and go about your business as usual.

So I have created a controller under 'app > controllers > navigation.php', and added:

`<?php

namespace App\Controllers;

use Log1x\Navi\Navi;

return (new Navi())->build('primary_navigation');
`
And created my blade partial for this, but still not showing. See attached for ref. Do I have to register the controller somewhere?

Screenshot 2019-12-17 at 00 49 12

Log1x commented

Sage 9's soberwp/controller is a little silly and depends on a body class for the Controller to work.

I'd just put it in app.php. Navigation is a global thing anyway.

Sorry, what code do I add in app.php, and where:

`<?php

namespace App\Controllers;

use Sober\Controller\Controller;

class App extends Controller
{
public static function title()
{
if (is_home()) {
if ($home = get_option('page_for_posts', true)) {
return get_the_title($home);
}
return ('Latest Posts', 'sage');
}
if (is_archive()) {
return get_the_archive_title();
}
if (is_search()) {
return sprintf(
('Search Results for %s', 'sage'), get_search_query());
}
if (is_404()) {
return __('Not Found', 'sage');
}
return get_the_title();
}
}
`

Log1x commented
<?php

namespace App\Controllers;

use Sober\Controller\Controller;
use Log1x\Navi\Navi;

class App extends Controller
{
    public function navigation()
    {
        return (new Navi())->build('primary_navigation');
    }

    public function siteName()
    {
        return get_bloginfo('name');
    }

    public static function title()
    {
        if (is_home()) {
            if ($home = get_option('page_for_posts', true)) {
                return get_the_title($home);
            }
            return __('Latest Posts', 'sage');
        }
        if (is_archive()) {
            return get_the_archive_title();
        }
        if (is_search()) {
            return sprintf(__('Search Results for %s', 'sage'), get_search_query());
        }
        if (is_404()) {
            return __('Not Found', 'sage');
        }
        return get_the_title();
    }
}

then use @foreach ($navigation->toArray() as $item) ... @endforeach in your view.

You're a legend!!!

Thanks so much, this worked perfectly.

Cheers.

Log1x commented

no problem