django-sitetree
django-sitetree copied to clipboard
Render menu starting at certain depth
I need to render a sites submenu which always starts with the tree items beginning with depth 3 (assuming that root is depth 1).
I do not see a way to do this with sitetree_menu(). this-siblings etc will not work in that case, as far as I understand it. What I would need is something like
{% sitetree_menu from "nav" include "trunk-depth-3" %}
Any way to do that?
To clarify - let's assume the tree looks like this:
Root
- A
- - A1
- - A2
- B
- - B1
- - - B1A
- - B2
- C
I need the tree to always start at the third level. Soi if A1 is active, the menu would show:
A1 A2
If B1 OR B1A were active, the menu would be: B1 -B1A B2
ps: I realized I can do this with 2 custom templates that do not render anything for the first two levels, but that's really awkward.
Any way to do that?
No, currently no. Yet it was already proposed in some issue or even a pull request some time ago, if I'm not mistaken.
There are some questions to answer before it could be implemented: 1. 3 or any other number basically says nothing to a person making a template?; 2. if a tree is restructured will it take to also update templates and swap one obscure number to another?
Wouldn't it be more proper for your use case to try and use two different trees?
Closing this. Feel free to reopen if any updates.
Hi!
I need this feature too, and I have a idea how to implement it.
We can set 'breakpoint' on menu item and stop on it climbing up the tree from current item.
According to example above:
- A
- - A1
- - A2
- B
- - B1
- - - B1A
- - B2
- C
We can set 'breakpoint' named 'example' on "A" and "B" items and get that we need in template calling {% sitetree_menu from "nav" breakpoint='example' %}. It looks clear, as for me.
@vit-ivanov Hi,
Looks somewhat unclear to me: why do you want to set two breakpoints. What if someone put four, six, etc.? Thta breakpoint
is it alias or an additional field?
Generally this issue is about limiting rendering depth down but not up the tree.
- Root
- - A
- - - A1
- - - A2
- - B
- - - B1
- - - - B1A
- - - B2
- - C
The goal is to start rendering
- from "A" then current item is "A1"
- from "B" then current item is "B1" or "B1A".
Possibly we can start rendering from certain level, but it looks like bad idea — it's not a solution for some menu configurations. My proposal is to mark "A" and "B" as stop points and stop climbing up on them.
Maybe russian? :))) skype, gtalk, icq etc
why do you want to set two breakpoints. What if someone put four, six, etc.? Thta breakpoint is it alias or an additional field?
Breakpoint is an additional field.
Guess I got what you're up to. Need a couple of days to think that over, yet.
Maybe russian? :))) skype, gtalk, icq etc
Possibly if I have some additional questions %)
For now let's reopen the issue to not to forget.
Seems interesting. Yet we probably should change breakpoint
for something less associated with hooks. Maybe call that field scope marker
. Than we could introduce sitetree_menu
tag optional clause scope
and allow it to accept slicing-style value to be able to limit rendering both up and down.
Example: {% sitetree_menu from "nav" include "trunk" scope "upper_scope_marker:lower_scope_marker" %}.
That's needs to be further analysed.