How to change the “current” class to “active” in KNPMenuBundle

你说的曾经没有我的故事 提交于 2019-12-18 16:09:07

问题


I was wondering, what is the best way to change the "current" class to be "active" so Bootstrap will work correctly with it?

I thought about copying and overriding the knp_menu_html.twig but i think its not the best way...

Anyway better doing it?


回答1:


You can pass it like that:

{{ knp_menu_render('AcmeDemoBundle:Builder:mainMenu', {'currentClass': 'active'}) }}



回答2:


To apply default options in all your application, you can set the knp_menu.renderer.twig.options parameter like this:

// app/config/services.yml
parameters:
    knp_menu.renderer.twig.options:
        currentClass: active

Default options of the Knp\Menu\Renderer\TwigRenderer are:

    $this->defaultOptions = array_merge(array(
        'depth' => null,
        'matchingDepth' => null,
        'currentAsLink' => true,
        'currentClass' => 'current',
        'ancestorClass' => 'current_ancestor',
        'firstClass' => 'first',
        'lastClass' => 'last',
        'template' => $template,
        'compressed' => false,
        'allow_safe_labels' => false,
        'clear_matcher' => true,
        'leaf_class' => null,
        'branch_class' => null,
    ), $defaultOptions);


来源:https://stackoverflow.com/questions/24120855/how-to-change-the-current-class-to-active-in-knpmenubundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!