如何在KNPMenuBundle中将"当前"类更改为"活动"

dor*_*ron 9 symfony knpmenubundle

我想知道,将"当前"类更改为"活动"的最佳方法是什么,以便Bootstrap可以正常使用它?

我想过复制和覆盖knp_menu_html.twig,但我认为这不是最好的方法......

无论如何做得更好?

Lio*_*ard 22

要在所有应用程序中应用默认选项,可以设置如下knp_menu.renderer.twig.options参数:

// app/config/services.yml
parameters:
    knp_menu.renderer.twig.options:
        currentClass: active
Run Code Online (Sandbox Code Playgroud)

默认选项Knp\Menu\Renderer\TwigRenderer是:

    $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);
Run Code Online (Sandbox Code Playgroud)


Bar*_*tek 20

你可以这样传递它:

{{ knp_menu_render('AcmeDemoBundle:Builder:mainMenu', {'currentClass': 'active'}) }}
Run Code Online (Sandbox Code Playgroud)