Created
April 1, 2012 20:24
-
-
Save mrflory/2278437 to your computer and use it in GitHub Desktop.
Twitter Bootstrap Twig Template for KnpMenuBundle in Symfony2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Linkofy\CommonBundle\Menu; | |
use Knp\Menu\FactoryInterface; | |
use Symfony\Component\DependencyInjection\ContainerAware; | |
class Builder extends ContainerAware | |
{ | |
public function mainMenu(FactoryInterface $factory, array $options) | |
{ | |
$menu = $factory->createItem('root'); | |
$menu->setChildrenAttribute('class', 'nav pull-right'); | |
$menu->addChild('User') | |
->setAttribute('dropdown', true); | |
$menu['User']->addChild('Profile', array('uri' => '#')) | |
->setAttribute('divider_append', true); | |
$menu['User']->addChild('Logout', array('uri' => '#')); | |
$menu->addChild('Language') | |
->setAttribute('dropdown', true) | |
->setAttribute('divider_prepend', true); | |
$menu['Language']->addChild('Deutsch', array('uri' => '#')); | |
$menu['Language']->addChild('English', array('uri' => '#')); | |
return $menu; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ knp_menu_render('LinkofyCommonBundle:Builder:mainMenu', {'currentClass': 'active'}) }} |
@hpatoio Replace it by "matcher.isAncestor(item, options.depth)" like in the original template.
I've forked this gist to fix the bug reported by @hpatoio
I've also added the ability to handle submenus.
Great! Thanks @mrflory !
Is there a version for Bootstrap3 for the twig file ?
very cool , thanks a lot ! @mrflory
I've made updates to these tut files (http://bit.ly/1sd1rJr) to work with Bootstrap 3 and Font Awesome 4. You really only need to change the MenuBuilder.php file and the index.html.twig file to update sources and classes.
very cool!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I'm trying to use your template but I get this error message:
I'm on Symfony 2.1.4