Skip to content

Instantly share code, notes, and snippets.

@nacmartin
Created March 9, 2012 19:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nacmartin/2008268 to your computer and use it in GitHub Desktop.
Save nacmartin/2008268 to your computer and use it in GitHub Desktop.
knpmenu + twitter bootstrap
<?php
class Builder extends ContainerAware
{
public function adminMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->setChildrenAttribute('class', 'nav'); //esto es el tema
$menu->setCurrentUri($this->container->get('request')->getRequestUri());
...
{% Con dropdown %}
{% extends "knp_menu.html.twig" %}
{% block list %}
{% import "knp_menu.html.twig" as macros %}
{% set is_dropdown = listAttributes.dropdown|default(false) %}
{% set divider_prepend = listAttributes.divider_prepend|default(false) %}
{% set divider_append = listAttributes.divider_append|default(false) %}
{# unset bootstrap specific attributes #}
{% set listAttributes = listAttributes|merge({'dropdown': null, 'divider_prepend': null, 'divider_append': null }) %}
{% if item.hasChildren and options.depth is not sameas(0) and item.displayChildren %}
{% if is_dropdown %}
<ul{{ macros.attributes(listAttributes)}}>
{% if divider_prepend %}
<li class="divider-vertical"></li>
{% endif %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ item.label }} <b class="caret"></b></a>
<ul class="dropdown-menu">
{{ block('children') }}
</ul>
</li>
{% if divider_append %}
<li class="divider-vertical"></li>
{% endif %}
</ul>
{% else %}
{{ parent() }}
{% endif %}
{% endif %}
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment