Custom Menu Presenters
-
Hi, I am creating a custom menu presenter to render menus according to Zurb Foundation Menus.
I have created my customer presenter
App\Presenters\ZurbMenuPresenter
and can get it to render using either of the following in my view:-{!! Menu::render('main', 'App\Presenters\ZurbMenuPresenter') !!}
{!! Menu::get('main', 'App\Presenters\ZurbMenuPresenter') !!}
@menu('main', 'App\Presenters\ZurbMenuPresenter' )
The above approaches do not appear to require me to register the presenter anywhere.
However, in order to better understand how AsgardCMS works "under the hood" I wanted to know how to register the presenter, and what effect that has. My understanding so far is that registering it will allow me to do something like
{!! Menu::get('main', 'zurb-menu') !!}
rather than passing the full path of the presenter.I have tried registering it in
config/asgard/menu/config.php
but apparently that makes no difference (I still have to pass'App\Presenters\ZurbMenuPresenter'
in my view).
I have also tried registering it inconfig/menus.php
following instruction in the docs here . Still no difference.I have even tried setting it as the default presenter in
config/asgard/menu/config.php
by setting'default_menu_presenter' => 'App\Presenters\ZurbMenuPresenter'
. Still no difference.How are you actually meant to register a presenter?! Why doesn't the
default_menu_presenter
work?Thanks in advance.
-
Hello,
I see the laravel-menus package configuration isn't published by default. Did you do that (I assume you did since you're talked about editing that file)?
php artisan vendor:publish --provider="Nwidart\Menus\MenusServiceProvider"
After this you'll have a config/menu.php file.
I don't use this feature myself, but if there's a bug here it should be submitted to the laravel-menus package itself to have it resolved if so.
Did you try using one of the default presenters available like
sidebar
ornav-pills
?
-
Hello,
So to register shortcut for presenter you would add it to
config/menus.php
oflaravel-menus
package.<?php return [ 'styles' => [ 'navbar' => \Nwidart\Menus\Presenters\Bootstrap\NavbarPresenter::class, 'navbar-right' => \Nwidart\Menus\Presenters\Bootstrap\NavbarRightPresenter::class, 'nav-pills' => \Nwidart\Menus\Presenters\Bootstrap\NavPillsPresenter::class, 'nav-tab' => \Nwidart\Menus\Presenters\Bootstrap\NavTabPresenter::class, 'sidebar' => \Nwidart\Menus\Presenters\Bootstrap\SidebarMenuPresenter::class, 'navmenu' => \Nwidart\Menus\Presenters\Bootstrap\NavMenuPresenter::class, 'my-custom_style' => \App\Presenters\ZurbMenuPresenter::class, ], 'ordering' => false, ];
After that you should be able to use it right away.
Try to clear caches and all that jazz.
I'm using multiple custom presenters myself and they are working just fine.The
default_menu_presenter
also works for me.
-
Hi, thanks for your help. No I didn't publish the laravel-menus package, so I've done that now, and see that the config file was copied from
laravel-menus/config
toconfig
. I can now also see that the definition should be in thestyles
array like so:return [ 'styles' => [ 'navbar' => \Nwidart\Menus\Presenters\Bootstrap\NavbarPresenter::class, 'navbar-right' => \Nwidart\Menus\Presenters\Bootstrap\NavbarRightPresenter::class, 'nav-pills' => \Nwidart\Menus\Presenters\Bootstrap\NavPillsPresenter::class, 'nav-tab' => \Nwidart\Menus\Presenters\Bootstrap\NavTabPresenter::class, 'sidebar' => \Nwidart\Menus\Presenters\Bootstrap\SidebarMenuPresenter::class, 'navmenu' => \Nwidart\Menus\Presenters\Bootstrap\NavMenuPresenter::class, 'zurbmenu' => \App\Presenters\ZurbMenuPresenter::class, ], 'ordering' => false, ];
And now it is working as expected. Many thanks. The example in the docs simply has the config like so..
return [ 'navbar' => 'Nwidart\Menus\Presenters\Bootstrap\NavbarPresenter', 'navbar-right' => 'Nwidart\Menus\Presenters\Bootstrap\NavbarRightPresenter', 'nav-pills' => 'Nwidart\Menus\Presenters\Bootstrap\NavPillsPresenter', 'nav-tab' => 'Nwidart\Menus\Presenters\Bootstrap\NavTabPresenter', 'zurb-top-bar' => 'ZurbTopBarPresenter', ];
Thanks anyway though
-
Hi, thanks. I didn't want to change the
laravel-menus
config file as otherwise it might break when updating.But anyway, i have copied the config over to
config/menus.php
and now that my presenter is registered correctly I can also do'default_menu_presenter' => 'zurbmenu'
Thanks again
-
Hi @pavsid,
I am working on same Zurb Foundation Menus, could you please share your ZurbMenuPresenter Code here, I just want to get some idea?
Thank you,
Kashif
-
After reading different posts for Zurb Presenter I have finally completed Presenter for Zurb Navigation and I have added a gist link below so that it may help someone:
https://gist.github.com/kashifullahwebdeveloper/c0eb423bf17797d0be0e2234948f3fd4
Thank you @nWidart.
-
Nice @kashifullahwebdeveloper !
Might be nice to PR this to laravel-menus so others can use out of the box too.
-
@nWidart. Thank you for the idea.
I have pulled latest changes from your repo, https://github.com/nWidart/laravel-menus, and request for Pull Request, but it gives me this error: Sync failed to Push local changes (permission issue).
Could you please tell me how can I request for Pull Request?
Thank you,
Kashif
-
You need to fork the repository first.
-
Thank you, @nWidart.
I have forked and then requested a Pull Request and done.