Questions tagged [knpmenu]

The KnpMenu library provides object oriented menus for PHP 5.3 which can be used with or without Symfony 2.

The KnpMenu library provides object oriented menus for PHP 5.3 which can be used with or without Symfony 2.

Since it always a problem to create menu: manage childs, define who is active, etc ... and can become a headache to code and maintain. This library solves the issue by giving you a small, yet powerful and flexible framework for handling your menus.

Basic questions that can be posted for this tag could be:

  • how to customize the renderer?
  • how to define a nested for an array?
  • how can I use it with Twig instead of PHP as template engine?

Useful links:

48 questions
12
votes
3 answers

How to disable HTML escaping of labels in KnpMenuBundle

I want to render an HTML label like: $menu->addChild('Dashboard', array( 'route' => 'dashboard', 'label' => ' Dashboard', 'extra' => array('safe_label' => true) …
Bartosz Rychlicki
  • 1,918
  • 3
  • 20
  • 41
6
votes
3 answers

KnpMenuBundle - how can i set an icon class to each elements of menu?

I want to my view code looks like this:
  • Title
  • I create menu elements by Menu Builder: class Builder extends…
    klapaucius
    • 111
    • 3
    • 11
    4
    votes
    2 answers

    How to create a breadcrumb with KNP Menu Bundle 2?

    So I have a menu built as shown in the example below:
    breq
    • 24,412
    • 26
    • 65
    • 106
    4
    votes
    4 answers

    KnpMenu, unable to set current menu item

    I have seen the other errors about this problem. I have done the exact same thing. When I try to render the menu I get this Fatal error: Fatal error: Call to undefined method Knp\Menu\MenuItem::setCurrentUri() in ProjectBundle/Menu/Builder.php on…
    tolgap
    • 9,629
    • 10
    • 51
    • 65
    4
    votes
    1 answer

    Symfony 2.0 KnpMenu custom template

    Im trying to modify template from knpMenu. I renamed it to knp_main_menu.html.twig config.yml: knp_menu: twig: template: knp_main_menu.html.twig templating: true default_renderer: twig knp_menu.html.twig works but my file (exact…
    Kaminari
    • 1,387
    • 3
    • 17
    • 32
    3
    votes
    0 answers

    Set current only one item with RegexVoter from KnpMenu

    I use the regexVoter from knpMenu like this //This is on my createMenuAction $this->matchingRoute($menu); /** * @param $menu * * @return bool */ private function matchingRoute($menu) { foreach ($menu->getChildren() as $child) { …
    Jérôme
    • 1,966
    • 4
    • 24
    • 48
    3
    votes
    0 answers

    KnpMenuBundle - current class on all subpages

    I create a menu by KnpMenuBundle class Builder extends ContainerAware { public function adminMenu(FactoryInterface $factory, array $options) { $menu = $factory->createItem('root'); $menu->addChild('Object', array( …
    klapaucius
    • 111
    • 3
    • 11
    3
    votes
    1 answer

    Render custom attribute KNP Menu

    Is there a way to render a custom attribute in the KNP Menu Bundle, something like this: $menu = $factory->createItem(Role::ROLE_PROGRAM_EVENT_PLANNER, array( 'route' => 'show_form_events', 'attributes' => array('class' => 'menu…
    xfscrypt
    • 16
    • 5
    • 28
    • 59
    3
    votes
    2 answers

    Symfony2 KnpMenuBundle children with dynamic parameters

    Let's say I have a routing setup like that : users_list: pattern: /users defaults: { _controller: AcmeBundle:User:list } user_edit: pattern: /user-edit/{id} defaults: { _controller: AcmeBundle:User:edit } I would like to setup a…
    Thomas Piard
    • 1,209
    • 2
    • 15
    • 25
    2
    votes
    1 answer

    Symfony 5.0 and KnpMenuBundle - how to configure

    In a Symfony 5.0 Application I want to use the KnpMenuBundle. I installed it by running composer require knplabs/knp-menu-bundle "^3.0" This automatically created an entry in…
    user3440145
    • 793
    • 10
    • 34
    2
    votes
    1 answer

    How to exclude certain string from showing up in missing translations using KnpMenuBundle and Symfony3

    Introduction In my personal project I am using: XAMPP with PHP v7.1.6 Symfony v3.3.8 KnpMnenuBundle dev-master / 2.2.x-dev (dev version because it is compatible with current Symfony 3.3.x version, earlier versions did not install via composer.)…
    Rikijs
    • 728
    • 1
    • 12
    • 48
    2
    votes
    1 answer

    symfony2 knpmenu unable to dropdown

    I am trying to create a dropdown navigation menu for my website using knpmenu. base.html.twig {% block title %}Inconix Intranet{% endblock %} -…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/php" class="post-tag grid--cell" title="show questions tagged 'php'" rel="tag">php</a> <a href="../../questions/tagged/symfony" class="post-tag grid--cell" title="show questions tagged 'symfony'" rel="tag">symfony</a> <a href="../../questions/tagged/knpmenu" class="post-tag grid--cell" title="show questions tagged 'knpmenu'" rel="tag">knpmenu</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Oct 14 '15 at 12:00">asked Oct 14 '15 at 12:00</time> <a href="../../users/1051167/blue-eye" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/1051167.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Blue Eye" /> </a> <div class="s-user-card--info"> <a href="../../users/1051167/blue-eye" class="s-user-card--link">Blue Eye</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">49</li> <li class="s-award-bling s-award-bling__silver" title="1 silver badges">1</li> <li class="s-award-bling s-award-bling__bronze" title="9 bronze badges">9</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-29208192"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>2</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status "> <strong>0</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/29208192/knpmenu-add-attribute-to-menuitem-class" class="question-hyperlink">KnpMenu: add attribute to MenuItem class</a></h3> <div class="excerpt">I am using KnpMenu with Symfony2.3 through the KnpMenuBundle. I would like to customize the class MenuItem by adding an attribute, the simplest way. The aim is to be able to link any MenuItem to one of my application's entity, and to retrieve it…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/php" class="post-tag grid--cell" title="show questions tagged 'php'" rel="tag">php</a> <a href="../../questions/tagged/symfony" class="post-tag grid--cell" title="show questions tagged 'symfony'" rel="tag">symfony</a> <a href="../../questions/tagged/knpmenubundle" class="post-tag grid--cell" title="show questions tagged 'knpmenubundle'" rel="tag">knpmenubundle</a> <a href="../../questions/tagged/knpmenu" class="post-tag grid--cell" title="show questions tagged 'knpmenu'" rel="tag">knpmenu</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Mar 23 '15 at 10:40">asked Mar 23 '15 at 10:40</time> <a href="../../users/2955738/blacksad" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/2955738.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Blacksad" /> </a> <div class="s-user-card--info"> <a href="../../users/2955738/blacksad" class="s-user-card--link">Blacksad</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">1,230</li> <li class="s-award-bling s-award-bling__gold" title="1 gold badge">1</li> <li class="s-award-bling s-award-bling__silver" title="14 silver badge">14</li> <li class="s-award-bling s-award-bling__bronze" title="23 bronze badge">23</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-28009619"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>2</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>1</strong> answer </div> </div> </div> <div class="summary"> <h3><a href="../../questions/28009619/remove-routevoter-on-a-knpmenu" class="question-hyperlink">Remove RouteVoter on a KnpMenu</a></h3> <div class="excerpt">Each bundle of the extranet is a independent application. In my menu every app is listed and I like to mark the current one depending the actual route prefix. First the twig code in the base.html.twig: {{…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/php" class="post-tag grid--cell" title="show questions tagged 'php'" rel="tag">php</a> <a href="../../questions/tagged/symfony" class="post-tag grid--cell" title="show questions tagged 'symfony'" rel="tag">symfony</a> <a href="../../questions/tagged/knpmenubundle" class="post-tag grid--cell" title="show questions tagged 'knpmenubundle'" rel="tag">knpmenubundle</a> <a href="../../questions/tagged/knpmenu" class="post-tag grid--cell" title="show questions tagged 'knpmenu'" rel="tag">knpmenu</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Jan 18 '15 at 12:25">asked Jan 18 '15 at 12:25</time> <a href="../../users/3173572/binzram" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/3173572.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="binzram" /> </a> <div class="s-user-card--info"> <a href="../../users/3173572/binzram" class="s-user-card--link">binzram</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">530</li> <li class="s-award-bling s-award-bling__silver" title="4 silver badges">4</li> <li class="s-award-bling s-award-bling__bronze" title="13 bronze badges">13</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="s-pagination pager fr"> <div class="s-pagination--item is-selected">1</div> <a class="s-pagination--item" href="../../questions/tagged/knpmenu_page=2" rel="" title="Go to page 2">2</a> <a class="s-pagination--item" href="../../questions/tagged/knpmenu_page=3" rel="" title="Go to page 3">3</a> <a class="s-pagination--item" href="../../questions/tagged/knpmenu_page=4" rel="" title="Go to page 4">4</a> <a class="s-pagination--item" href="../../questions/tagged/knpmenu_page=2" rel="next" title="Go to page 2"> Next</a> </div> </div> </div> </div> </div> <script src="../../static/js/stack-icons.js"></script> <script src="../../static/js/fromnow.js"></script> </body> </html>