Feat: option to retain child menu items when visible=False #143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the option for child menu items to not be removed from the list when
item.visible == False
.Usecase
I am using django-simple-menu both for menu items and for breadcrumb generation. There are several cases where a menu item is not visible to click, but can produce an entry in the breadcrumb trail.
As a work-around (and due to the simplicity of the site structure I am working on at present) I have been able to get away with simply leaving visible=True on all items and not rendering any child items. This will not work forever though.
The change
This change adds a new setting
MENU_TRIM_NON_VISIBLE_CHILD_ITEMS
which defaults to the existing behaviour of removing all non-visible child items, but, it can be set toFalse
which will then retain these items. As such, this is a non-breaking change for existing users.The default templates in this repo should work either way because
item.visible
is always checked, but I can appreciate that some people will have custom templates which do not perform this check.I've added some tests, but please let me know if there's anything further I can do to help get this merged in.