Open dwasyl opened 4 years ago
Sorry for the delay. Actually such behaviour is expected.
As a fix, I think sitetree should attempting matching this against all possible urls, not just the first one returned.
You've already mentioned that there are multiple matches, so how should we define and detect the "best" match in that case? I'm afraid there's no universal heuristic for that. Do you have one in mind?
@idlesign It's okay, I think it's a bit different than the intended behaviour with multiple matches.
Using the setup I posted above if a user accesses http://site.com/books/1/
, sitetree
would display the menu as specified based on this
being equal to item("{{ obj }}", "book_view obj.pk")
this menu item.
However, if a user accesses http://site.com/library/books/1/
, sitetree
would have no matching value for this
and then the sitetree_menu
command as specified wouldn't display anything. If you were to comment out the first urls.py
path then accessing it via the second url would match to this
.
So I don't think this is an issue where there needs to be a "best" match, but since either path meets the specified item
then either should be matched with this
.
At the same time, when generating a link for that menu item, sitetree just picks the first matching url which is the current and likely best solution.
In continuing to setup this package I stumbled across a bug in how
sitetree
matches urls. When there are multiple matches to the same URL,sitetree
only tries to match against the first possible url match, not the entire list.With the code setup below, if I was on a page say:
/books/1/
the page would print the side menu setup below just fine, however, if I was on/library/books/1/
thesitetree_menu
include forthis-parent-siblings
doesn't find a match forthis
(and so displays nothing). When I comment out the first matching URL, the/library/books/1/
matchesthis
just fine.As a fix, I think
sitetree
should attempting matchingthis
against all possible urls, not just the first one returned.Here's the setup: An url structure something like this:
A dynamic menu setup like this:
Sidebar menus are display with the menu templatetag:
{% sitetree_menu from "main-tree" include "this-parent-siblings" %}