覆盖symfony2的knp菜单包中的选项

时间:2016-06-20 16:06:25

标签: symfony override option knpmenubundle

从默认的knp菜单包模板:

{%- elseif matcher.isAncestor(item, options.matchingDepth) %}
    {%- set classes = classes|merge([options.ancestorClass]) %}

options.ancestorClass等于' current_ancestor'。有没有办法覆盖这个?我不想复制涵盖50行代码的wohle块项目代码,我只需要更改一个值。

最佳

基督教

1 个答案:

答案 0 :(得分:1)

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

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

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);

尝试

{{ knp_menu_render('AcmeDemoBundle:Builder:mainMenu', {'ancestorClass': 'your-class'}) }}

来自this link