-
Notifications
You must be signed in to change notification settings - Fork 194
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
How to display children, if parent is current. #84
Comments
From my tests it appears that the item in question has not been evaluated as current yet by the time the children are rendered. Is that correct? |
I've found a way to do it, just need to find a way to make it a config option. If you change line 74 of the twig template from
to {% if matcher.isCurrent(item) %}
{{ block('list') }}
{% endif %} Then the children are only displayed for current parent items. Your thoughts? |
Scratch that, that has a problem, as soon as you select a child item, the parent is no longer current and they are not rendered. Hmmmm. So what is really needed is to render children if any of the following are true.
|
So this is working, but how is best to make the functionality part of the core menu code? {% set childIsActive = false %}
{% for child in item.children if matcher.isCurrent(child) %}
{% set childIsActive = true %}
{% endfor %}
{% if matcher.isCurrent(item) or childIsActive %}
{{ block('list') }}
{% endif %} |
@catchamonkey the matcher has |
@stof Hi, Thanks for that, much cleaner here; {% if matcher.isCurrent(item) or matcher.isAncestor(item) %}
{{ block('list') }}
{% endif %} Would be great to make that a configurable part of the menu system, works better for nested nav in some contexts. |
Hi @stof I'm going to put in a PR to add this to the menu item so it's available to all. https://github.com/catchamonkey/KnpMenu/compare/display_children_if_ancestor_current |
children of a menu item, if the item itself, or the ancestor is 'current'. Closes KnpLabs#84
PR opened, closing this now. |
Hi,
Loving the library here, stopped me porting my Symfony 1.4 plugin over so thanks!
One thing I can't work out though, is if you define a few menu items, and some of them have children, how can you render the children of only the current menu item?
I only want My Comments (and it's siblings ul) to be rendered if Comments is the active menu item.
Any ideas?
The text was updated successfully, but these errors were encountered: