Twill navigation group

Any easier way to achive grouping by title in the primary navigation which is not module nor singleton. This is achivable via legacy, but I want to stick to the new OOP way, but it seems that its not working or I am missing something. I partialy achived this via external url, but it has some issue. AppServiceProvider
TwillNavigation::addLink(
NavigationLink::make()
->title('Music')
->toExternalUrl(route('twill.music.albums.index'))
->setChildren([
NavigationLink::make()
->forModule('albums')
->title('Albums'),
NavigationLink::make()
->forModule('songs')
->title('Songs')
])
);
TwillNavigation::addLink(
NavigationLink::make()
->title('Music')
->toExternalUrl(route('twill.music.albums.index'))
->setChildren([
NavigationLink::make()
->forModule('albums')
->title('Albums'),
NavigationLink::make()
->forModule('songs')
->title('Songs')
])
);
twill.php
Route::group(['prefix' => 'music'], function () {
TwillRoutes::module('albums');
TwillRoutes::module('songs');
});
Route::group(['prefix' => 'music'], function () {
TwillRoutes::module('albums');
TwillRoutes::module('songs');
});
Result:
No description
8 Replies
kallefrombosnia
kallefrombosnia•12mo ago
Okay, this works fine right now with this method ->doNotAddSelfAsFirstChild()
geetpurwar
geetpurwar•12mo ago
@kallefrombosnia Can you post complete code. I want top child to be custom name which doesn't connect to any module or singleton
kallefrombosnia
kallefrombosnia•12mo ago
This is exactly that and full code is provided. I asked is there any better way to do this, but I dont see it. This is the latest change.
TwillNavigation::addLink(
NavigationLink::make()
->title('Music')
->toExternalUrl(route('twill.music.albums.index'))
->doNotAddSelfAsFirstChild()
->setChildren([
NavigationLink::make()
->forModule('albums')
->title('Albums'),
NavigationLink::make()
->forModule('songs')
->title('Songs')
])
);
TwillNavigation::addLink(
NavigationLink::make()
->title('Music')
->toExternalUrl(route('twill.music.albums.index'))
->doNotAddSelfAsFirstChild()
->setChildren([
NavigationLink::make()
->forModule('albums')
->title('Albums'),
NavigationLink::make()
->forModule('songs')
->title('Songs')
])
);
geetpurwar
geetpurwar•12mo ago
Let me check and I will let you know what works for me
pauldwight
pauldwight•12mo ago
@kallefrombosnia instead of using the toExternalUrl I would personally set it the forModule('albums') for your primary Music link - otherwise i do the same as what you have done
kallefrombosnia
kallefrombosnia•12mo ago
I'd like to keep it seperated like two children items. This was really easy to achive via legacy navigation but Ill stick to OOP for now. Thank you for considaration. 🙂
'music' => [
'title' => 'Music',
'route' => 'admin.music.albums.index',
'primary_navigation' => [
...
'music' => [
'title' => 'Music',
'route' => 'admin.music.albums.index',
'primary_navigation' => [
...
ifox
ifox•12mo ago
I'm not sure I get why you're using toExternalUrl when there is forRoute and forModule https://twillcms.com/docs/api/3.x/A17/Twill/View/Components/Navigation/NavigationLink.html#method_forRoute
kallefrombosnia
kallefrombosnia•12mo ago
Damn, I missed this then. Ill try it ty @ifox.dev