I have a complex navigation which I'm building with Django CMS. In the navigation, there are three levels of pages. When rendering the level 2 navigation, I'd like to first display all level 2 pages that are leaf nodes in order, and then display all level 2 pages and their children.
Here's an example of what the tree structure is:
- Homepage
- About Us
- Level Two
- In Depth
- Who we are
- What we do
- Lorem Ipsum
- Contact Us
- Etcetera
The output should be something like this:
<ul>
<li>Homepage</li>
<li>About Us
<ul class="lvl-2">
<!-- All leaf nodes are grouped first -->
<li>Level Two</li>
<li>Lorem Ipsum</li>
<!-- Then the nodes with children after -->
<li>In Depth
<ul class="lvl-3">
<li>Who we are</li>
<li>What we do</li>
</ul>
</li>
</ul>
</li>
<li>Contact Us
<ul class="lvl-2">
<li>Etcetera</li>
</ul>
</li>
</ul>
I'd prefer to find a solution which does not require looping through the nodes twice. Thanks!