Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navbar depth 1 or displayChildren false #162

Closed
peshi opened this issue Dec 21, 2013 · 9 comments
Closed

Navbar depth 1 or displayChildren false #162

peshi opened this issue Dec 21, 2013 · 9 comments

Comments

@peshi
Copy link
Contributor

peshi commented Dec 21, 2013

Hello,

Is it possible to remove dropdown and caret and treat is as a normal link if I would like to use
{{ knp_menu_render('applicationMenu', {'type': 'navbar', 'depth': 1}) }}
or
{{ knp_menu_render('applicationMenu', {'type': 'navbar', 'displayChildren': false }) }}

@florianeckerstorfer
Copy link
Member

Sorry, I don't fully understand what you want to do. Can you give an example?

@peshi
Copy link
Contributor Author

peshi commented Dec 21, 2013

I would like to be able to use ->setDisplayChildren(false) in KnpMenuBundle either by doing it programmatically per menu item or by disabling all of them in Twig. The reason for it, is that my application is very big and I don't want to repeat myself writing more menu's or splitting it up, when I can use the menu structure I have already written once.

With the code below I can pull certain parts from my menu structure to sidebars and other places. And it would keep breadcrumbs intact.

{% set menuItem = knp_menu_get('AcmeDemoBundle:Builder:mainMenu', ['Contact']) %}
{{ knp_menu_render(menuItem) }}

I noticed after my post that item.displayChildren is present in bootstrap.html.twig on some parts of dropdowns, but not everywhere to eliminate the html and caret. I have two solutions for this issue and I'll post my results here when I have checked that it is working properly. You can then decide if you want to use it or if it is specific to my needs.

@peshi
Copy link
Contributor Author

peshi commented Dec 21, 2013

Ok, this solution works for me - I tried several options. Let me know if there is a smarter way to do it.

Replaced line 69 with

{% if item.hasChildren and options.depth is not sameas(0) and ((item.extras.dropdown is not defined and item.displayChildren is sameas(true) or item.extras.dropdown is defined and item.extras.dropdown is sameas(true) and item.displayChildren is sameas(true))) %}

Replaced line 120 with

{%- elseif item.hasChildren and options.type is defined and options.type in ['tabs', 'pills', 'navbar', 'navbar-right'] and ((item.extras.dropdown is not defined and item.displayChildren is sameas(true) or item.extras.dropdown is defined and item.extras.dropdown is sameas(true) and item.displayChildren is sameas(true))) %}

Replaced line 138-139 with

{%- elseif item.hasChildren and options.type is defined and options.type in ['tabs', 'pills', 'navbar', 'navbar-right'] and options.currentDepth is sameas(1) and ((item.extras.dropdown is not defined and item.displayChildren is sameas(true) or item.extras.dropdown is defined and item.extras.dropdown is sameas(true) and item.displayChildren is sameas(true))) %}
{{ block('dropdownElement') }}
{%- elseif item.hasChildren and options.type is defined and options.type in ['tabs', 'pills', 'navbar', 'navbar-right'] and options.currentDepth is sameas(1) and ((item.extras.dropdown is defined and item.extras.dropdown is sameas(false) or item.displayChildren(false) )) %}
{{ block('linkElement') }}

How to use it?
If you only want to disable the dropdown for a particular child/item you can use the extras for KnpMenuBundle.

$statistics = $root->addChild('Statistics', array('route' => 'some_route_index', 'extras' => array('dropdown' => false)));
$statistics->addChild('Graph Index', array('route' => 'some_route_graph'));

This would remove all html associated with the dropdown and it's children.
If you want to use the children from the disabled dropdown menu for a sidebar or somewhere else, it is possible to pull it out with

{% set menuItem = knp_menu_get('applicationMenu', ['Statistics']) %}
{{ knp_menu_render(menuItem, {'type': 'stacked-pills'}) }}

If you want to disable all children and not display any of them, you could use the default provided from KnpMenuBundle.

$statistics = $root->addChild('Statistics', array('route' => 'some_route_index'))->setDisplayChildren(false);
$statistics->addChild('Graph Index', array('route' => 'some_route_graph'));

Either way if you disable by extras dropdown false or all children with setDisplayChildren(false), it doesn't show a dropdown caret but a normal link.

You can close this issue at will.
Merry Christmas! :)

@florianeckerstorfer
Copy link
Member

Which version of BootstrapBundle do you use? Are you still on 1.x?

@peshi
Copy link
Contributor Author

peshi commented Dec 21, 2013

Oh, sorry I forgot to mention that I am referring to the 2.0 branch.

@florianeckerstorfer
Copy link
Member

I was asking because you used options.type instead of options.style(which is new since 2.0).

@peshi
Copy link
Contributor Author

peshi commented Dec 21, 2013

Ah, indeed - It seems that I'm fiddling in a old template in my sandbox next to the original. Thanks!

@peshi
Copy link
Contributor Author

peshi commented Dec 21, 2013

If i'm not mistaken it missing the the following else if and block of linkElement after LN: 139 ?

{%- elseif item.hasChildren and options.style is defined and options.style in ['tabs', 'pills', 'navbar', 'navbar-right'] and options.currentDepth is sameas(1) and ((item.extras.dropdown is defined and item.extras.dropdown is sameas(false) or item.displayChildren(false) )) %}
{{ block('linkElement') }}

@florianeckerstorfer
Copy link
Member

The original line was 140 was:

{%- elseif item.uri is not empty and ((matcher is defined and not matcher.isCurrent(item)) or options.currentAsLink) %}

Your line 140 is:

{%- elseif item.hasChildren and options.style is defined and options.style in ['tabs', 'pills', 'navbar', 'navbar-right'] and options.currentDepth is sameas(1) and ((item.extras.dropdown is defined and item.extras.dropdown is sameas(false) or item.displayChildren(false) )) %}

Since that can't be right I thought it was a copy and paste mistake. Can you take a look at it and fix it?

peshi added a commit to hyperunknown/bootstrap-bundle that referenced this issue Dec 22, 2013
florianeckerstorfer pushed a commit that referenced this issue Dec 28, 2013
…to develop

* 'develop' of github.com:braincrafted/bootstrap-bundle:
  Set correct default value for label_col
  Correction of PHPDoc for badgeFunction
  Second attempt Fix #162
  Fix #162
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants