How To Put A Page Under Active Menu Item with Django Sitetree

09 Oct · by Tim Kamanin · 1 min read

Django sitetree is a great app to manage your Django app menus. Sometimes, you'll have a page that you want to manually put under a sitetree, so how to do that? At first we need to patch a sitetreeapp.py like this:

@@ -288,6 +288,9 @@
 else:
 # urlquote is an attempt to support non-ascii in url.
 current_url = urlquote(self._global_context['request'].path)
+if self._global_context.get('sitetree_current_url'):
+current_url = self._global_context.get('sitetree_current_url')
+
 urls_cache = self.get_cache_entry('urls', tree_alias)
 if urls_cache:
 for url_item in urls_cache:

After that, you can set any menu item as active by just specifying its url in your view.py context, for example:

context['sitetree_current_url'] = '/some-url-path-that-you-want-to-set-as-an-active/'

Comments

Required for comment verification