KnpLabs / KnpLabs/KnpMenu

Add rootAttributes rendering option

Open
#166 14 comments 1 reaction 0 assignees View on GitHub
Improvement RFC
Dominant language
PHP
Stars
1.4k
Forks
189
PR merge metrics
No merged PRs in 30d

Description

Hi,

I want to set the root attributes of a menu from inside a Twig template. I am working on a project where different themes need to have different CSS classes for the menu, and it seems quite ugly to override the `MenuBuilder` just to change the `childAttributes` of the root item.

My suggestion is to add a `rootAttributes` option to the default renderers.

Example usage (Twig renderer):

``` twig
{# render Bootstrap nav #}
{{ knp_menu_render('main', {
'currentClass': 'active',
'rootAttributes': { class: 'nav navbar-nav' }
}) }}
```

If you agree, I could submit a PR with all necessary changes to the default renderers, docs and twig template.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting the default renderers, the Twig template, and the documentation mentioned in the issue, using the provided Twig example as the expected interface. The work is complete when the rootAttributes option is supported by all default renderers, documented, and applies the requested attributes to the rendered menu root.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.