В настоящее время я делаю меню с помощью пакета Symfony: KnpMenuBundle. Я использую Bootstrap 4 в качестве таблицы стилей.
Bootstrap 4 требует, чтобы каждый элемент списка на панели навигации имел класс nav-item:
<li class="nav-item active"> <-- this
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
Кажется, я не могу понять, как добавить класс «nav-item» к элементу списка с помощью KnpMenuBundle. В настоящее время при загрузке страницы я вижу следующее: результат навигационной панели
Это мой класс Builder в src / AppBundle / Menu:
namespace AppBundle\Menu;
use Knp\Menu\MenuFactory;
class Builder
{
public function mainMenu(MenuFactory $factory, array $optioins)
{
$menu = $factory->createItem('root');
$menu->setChildrenAttribute('class', 'navbar-nav mr-auto');
$menu->addChild('Home', ['route' => 'homepage']);
$menu->setChildrenAttributes(['class' => 'nav-item']);
return $menu;
}
}
Мой код в base.html.twig для создания меню:
{{ knp_menu_render('AppBundle:Builder:mainMenu', {'currentClass': 'active'}) }}
Что мне делать, чтобы он работал?