从默认的knp菜单包模板:
{%- elseif matcher.isAncestor(item, options.matchingDepth) %}
{%- set classes = classes|merge([options.ancestorClass]) %}
options.ancestorClass等于' current_ancestor'。有没有办法覆盖这个?我不想复制涵盖50行代码的wohle块项目代码,我只需要更改一个值。
最佳基督教
答案 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'}) }}