I'm using Asgard CMS in one of my prjects.
I'm trying to print a menu with custom classes.
By defaut, {{ Menu::get('main') }}
prints out the main menu with Bootstrap classes. But, I want to use different classes because of my theme.
In their documentation, they say that by creating a Presenter
you can do this. However, when I create a Presenter named CustomPresenter.php
with a class named CustomPresenter
that extends Pingpong/menus/Presenters/Presenter.php
, place it under /vendor/xxx/
and calling it by {{ Menu::render('main', 'XXX/CustomPresenter') }}
in my blade, Laravel gives Class 'XXX\CustomPresenter' not found error.
Here is the code I use in CustomPresenter:
namespace XXX;
use Pingpong\Menus\Presenters\Presenter;
class CustomPresenter extends Presenter
{
/**
* {@inheritdoc }
*/
public function getOpenTagWrapper()
{
return PHP_EOL . '<section class="top-bar-section">' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getCloseTagWrapper()
{
return PHP_EOL . '</section>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getMenuWithoutDropdownWrapper($item)
{
return '<li'.$this->getActiveState($item).'><a href="'. $item->getUrl() .'">'.$item->getIcon().' '.$item->title.'</a></li>';
}
/**
* {@inheritdoc }
*/
public function getActiveState($item)
{
return \Request::is($item->getRequest()) ? ' class="active"' : null;
}
/**
* {@inheritdoc }
*/
public function getDividerWrapper()
{
return '<li class="divider"></li>';
}
/**
* {@inheritdoc }
*/
public function getMenuWithDropDownWrapper($item)
{
return '<li>
<a href="#" class="sf-with-ul">
'.$item->getIcon().' '.$item->title.'
</a>
<ul style="display: none;">
'.$this->getChildMenuItems($item).'
</ul>
</li>' . PHP_EOL;
;
}
}
From official documentation:
To register this new presenter you need to add it to the package configuration (
config/packages/pingpong/menus/config.php
)
Did you do that?
return array(
'navbar' => 'Pingpong\Menus\Presenters\Bootstrap\NavbarPresenter',
'navbar-right' => 'Pingpong\Menus\Presenters\Bootstrap\NavbarRightPresenter',
'nav-pills' => 'Pingpong\Menus\Presenters\Bootstrap\NavPillsPresenter',
'nav-tab' => 'Pingpong\Menus\Presenters\Bootstrap\NavTabPresenter',
'zurb-top-bar' => 'ZurbTopBarPresenter',
);
Also documentation does not mention to place your class in vendor/xxx
directory. Main rules of using composer is to not editing vendor
directory manually. You should place your class in your app folder using your app namespace (directory App\Http\Presenters
would be best).