Implement custom navigation with the sitemap

By default Sitefinity CMS comes with a Navigation widget, see Navigation widget. Although it provides ability to customize the template, for one reason or another, a lot of developers decide to implement custom navigation. Some of the possible reasons is better control on what is displayed or styling the navigation in a way the navigation widget doesn’t support.

There are many ways you can implement a custom navigation. The first idea that comes to mind is using the PagesService in Sitefinity CMS. It will provide you with logic that is ready to be used to retrieve pages and populate the Navigation widget. However, as any of the Sitefinity CMS services each method of the PagesService requires authentication. This is not an option for a control whose purpose is to be used mainly on the frontend. The second idea that comes to mind is to create a custom web service and to use the Pages API. However this will not be an optimal solution in terms of performance. The Pages API exposes additional data, whcih is redundant for navigation widget purposes, thus this approach doesn’t scale. Navigation is one of those things that are rendered everywhere on your site and calling the API on each request is not exactly a performance best practice. Also note that filtering by permissions and current site (when in Multisite environment) and caching are not out-of-the-box provided with the Pages API.

The best solution is to use the Sitefinity CMS SiteMap provider (for example in a custom web service). This gives you better performance by utilizing caching and lazy loading – it only calls for data when needed. You can get an instance of the SiteMap provider in one of the following ways:

Once you have the provider, you can bind, following the ASP.NET standard. For more information, see the MSDN documentation.

For an example of an MVC navigation widget using the Sitefinity CMS SiteMap provider see this sample on the Sitefinity CMS GitHub repo.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?