Kontent.ai
Copyright © 2023 Kontent.ai. All rights reserved.
  • Web
  • Privacy policy
  • Cookies policy
  • Consent settings
  • Security
  • GDPR
  • Documentation
  • API reference
  • Product updates
Kontent.ai Learn
  • Plan
  • Set up
  • Model
  • Develop
  • Create

Choose your navigation approach

Is this page helpful?
Complete and continue
  • Sign in
    • JavaScript
      JavaScript
    • TypeScript
      TypeScript
    • .NET
      .NET
    • Java
      Java
    • PHP
      PHP
    • Ruby
      Ruby
    • REST
      REST
    Tomas Nosek
    10 minutes
    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.
    This way is better for larger projects prepared for omnichannel content.

    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 (Subitems)
    • A linked items element for the content itself
    • 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 the depth 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.
    What's next?
    Choose URL structure
    When building a web app, you need to decide what your URLs are going to look like. Do you need hierarchical URLs or short URLs? Do you need the URLs to be human-readable? Let's look at several options you can choose from.
    Separate navigation where pages in the page tree link to the actual content.
    • Develop with Kontent.ai
    • Hello World
    • Hello Web Spotlight
    • Run a sample app
    • Build apps
    • Decide navigation and URLs
    • Environments
    • Get Developer Certification
    • Choose navigation approach
    • Choose URL structure
    • Differentiate languages
    • Avoid 404s
    • C#
    Using Web Spotlight?If your project comes with Web Spotlight, some steps are already done for you. Check out what's created automatically after Web Spotlight is activated.
    Microsites and proofs of conceptIf you’re building a microsite or just a quick proof of concept and need navigation fast, you can hardcode the navigation. No part of your navigation is modeled in Kontent.ai; it’s all in the code. See our sample application as an example. We discourage using hardcoded navigation for larger live projects.
    // Tip: Find more about .NET SDKs at https://kontent.ai/learn/net
    using Kontent.Ai.Delivery;
    
    // Tip: Use DI for this in your apps https://kontent.ai/learn/net-register-client
    IDeliveryClient client = DeliveryClientBuilder
          .WithProjectId("8d20758c-d74c-4f59-ae04-ee928c0816b7")
          .Build();
    
    // Gets navigation items and their linked items
    // Tip: Create strongly typed models according to https://kontent.ai/learn/net-strong-types
    IDeliveryItemResponse<NavigationItem> rootResponse = await client.GetItemAsync<NavigationItem>("root_navigation_item",
        new DepthParameter(5)
        );
    
    NavigationItem root = rootResponse.Item;
    
    // Gets specific elements of all articles
    IDeliveryItemListingResponse<Article> articleResponse = await client.GetItemsAsync<Article>(
        new EqualsFilter("system.type", "article"),
        new ElementsParameter("title", "url")
        );
    
    var articles = articleResponse.Items;
  • Choose a suitable navigation approach
  • Build your navigation