When it comes to browsing a website, the navigation plays a crucial role in ensuring that users can easily find what they're looking for. In many content management systems the content is organised in a hierarchical content tree and a common pattern is to derive the navigational structure from that content tree. This pattern is observed in some popular CMSs such as Umbraco, Sitecore, and Optimizely.
The hierarchical content tree offers an advantage by resembling the familiar folder structure on computers. This resonates with many content editors who find this form of organising content more intuitive. The navigational structure is also "out of the box" – that is a double-edged sword. On one hand the navigational structure can simply be derived from the content tree, but on the other hand not all content in the CMS should be visible in the website's navigation.
How to implement this pattern
If you are in a headless environment, you need to create API endpoints that allow your frontend to fetch the navigation data. These endpoints can return the data in JSON format, making it easy for the frontend to consume.
On the frontend, use JavaScript to fetch the hierarchical content data from the API endpoints. You can then use JavaScript logic to build the navigation structure dynamically. This might involve iterating through the data and generating HTML elements based on the hierarchical relationships.
Consider implementing caching mechanisms to store the navigation data on the frontend. This reduces the need to fetch the data from the server repeatedly, improving performance. As you add, update, or remove content items, ensure that the cache is kept in sync or invalidated.
How to implement with Enterspeed
The navigation can, for instance, consist of all your pages or pages with a property called "Include in navigation" that you created in your CMS.
To do this, you must create two schemas: One for the individual navigation item and one for the entire navigation.
Let's start with the individual navigation item.
Schema: Navigation item