Choose your navigation approach
0% complete
Whether displayed as a website menu or navigation in your mobile app, navigation builds a hierarchy in your project.If you model your navigation, content creators can manage navigation menus without developer assistance.
Choose a suitable navigation approach
Navigation is composed of content items based on a content type dedicated to navigation. Define the relationships in the navigation using a subpages element if you use Web Spotlight or with a linked items element in other cases. When modeling the navigation, decide whether to bind content to the navigation or keep them separate.Navigation bound to content
This way, items that you link in the subpages or linked items element also hold the content. While this approach is more straightforward for understanding the concept, it isn’t suitable for omnichannel delivery. That’s why it’s more suitable for smaller projects or projects that use one way of navigation for all channels.Navigation separate from content
If you separate navigation from content, you’re creating two items for content linked from your navigation. The first is for the content itself; the second is for a navigation item that links the first one.Build your navigation
1. Create a content type for navigation items
Create a new content type and add elements needed for your channel. In the code examples below, this type is called the Navigation item. It typically contains:- A text element for the title of the navigation item (Title in the code sample)
- A subpages or linked items element for child menu items (Subpages)
- A linked items element for the content itself (Content)
- A URL slug element if you’re building website navigation (URL)
2. Define your root
You need to define where your navigation begins. While websites typically have a homepage, other structures may have a root or main screen. You can use the content type created for navigation for the root navigation item or create a different content type for this purpose. Websites usually benefit from having a separate content type for their homepage. That’s because homepages have a unique appearance and contain a different layout and content than other pages. The code example below uses the navigation item for the homepage, created with the name Root navigation item.3. Create your navigation items
Create content items using the created navigation content type and link them with the subpages or linked item element. When finished, publish the root together with all its linked items.4. Retrieve your navigation items
Developers now need to request the items via the Delivery API to generate your menu. Specify thedepth
parameter to retrieve more than one level of subpages or linked items if you want to show all navigation with one API call.
5. Display navigation
Using the retrieved data, display the navigation as you prefer. It can be your sections in a mobile app or smartwatch, or it can be a menu on a website like this:
The content of the linked items is inside the
modular_content
property of the response.
And that’s it! You now have a dynamic menu that your content creators can manage entirely from Kontent.ai.
Set up breadcrumbs for navigation
Sign in with your Kontent.ai credentials or sign up for free to unlock the full lesson, track your progress, and access exclusive expert insights and tips!