Especially with large amounts of content, tree structures can be handy because they can be used to represent the native structure of websites as the visitors see them. People tend to think in terms of pages, subpages, menus, submenus, and breadcrumb navigations. Hence, the tree structure of CMS objects comes naturally.
For creating and maintaining tree structures, every CMS object has a built-in _path
attribute to which values such as “/news/politics/article42” can be assigned programmatically. However, explicitly assigning a path to a CMS object should only be required in situations where content needs to be restructured using a script. With in-place editing, Scrivito automatically generates and assigns paths as editors add pages to the website using the menu of a rendered toclist
.
toclist
is a built-in method of non-binary CMS objects that returns their non-binary child objects. Rendered using the scrivito_tag_list
helper, editors will see a generated navigation that includes a menu with an item for creating a new page as part of this navigation. See Navigating the Page Hierarchy for details.
To programmatically traverse a hierarchy based on the _path
attribute, the parent
and children
instance methods are available: