Making Navigations Sortable

Making Navigations Sortable

Almost all website projects require a means to sort navigation items. As a Scrivito editor, you can simply click the handle of the navigation to open its menu, and click Sort items.

This opens a window that lets you move items to their desired location using drag and drop:

However, this option is only available if the page containing the navigation has been prepared for sorting the subordinate pages.

For subpages to be sortable, their parent page requires a custom attribute named child_order for remembering the order of the child pages. This attribute must be of the referencelist type, which serves to associate a CMS object with a sortable list of other CMS objects, which is exactly what is required here.

So, to make a parent's children sortable, add the child_order reference list to the parent's object class:

The child_order reference list is only taken into account if the list of children is rendered using scrivito_tag_list. If you need to iterate over the toclist of a page object and still want to take account of child_order, use (@obj.child_order & obj.toclist) | @obj.toclist.sort_by(&:id), or override Obj.toclist accordingly. See Navigating the Page Hierarchy for details on how to generate navigations.