CATEGORÍAS

ÚLTIMOS CURSOS

Here’s a commonly requested example of custom menu logic. Suppose you have primary navigation across the top of the site showing only primary pages, representing sections of the site. You then want to have a tree menu in a sidebar, that displays all pages within the section of the site currently being viewed. To achieve this we recursively move through the page tree, only drilling down through child pages if page.is_current_or_ascendant is True, or if the page isn’t a primary page. The key here is the page.is_current_or_ascendant check is only applied to the primary page, so all of its descendants end up being rendered. Finally, we also only display the link to each page if it isn’t the primary page for the section: