Add custom fields to the Navigation widget

Overview

You can customize your Navigation widget by creating custom fields for pages and displaying them and their values in the Navigation widget. For example, if you want to display multiple images in the Navigation widget, you can create a related media custom field for pages and add it to the Navigation widget template that you use – for example,  NavigationView.Horizontal.cshtml

The Navigation widget templates are located in the ~/MVC/Views/Navigation folder. Depending on what kind of template you are using, you can modify the corresponding view. For more information, see Resource packages.

This article shows how to add custom fields to the Navigation widget.
For more information, see Use custom fields in widget templates.

Add custom fields to MVC navigation widget

Once you create a custom field for pages, it is accessible via the model of the Navigation widget - Model.Nodes.

Each node in Model.Nodes is a NodeViewModel type and corresponds to the particular page you have created. To add the custom field, you need to reference the field through the CustomFields property of the node. For example, if you crated a new custom short text field, named ShortTitle, you can add it with the following reference: @node.CustomFields.ShortTitle.

The following sample demonstrates how to add custom fields of type Related media and Short text to Navigation widget with Horizontal template. For the purpose you need to edit the NavigationView.Horizontal.cshtml  located in ~/MVC/Views/Navigation folder. You can add the custom fields on either root or child level.

In the code below:

  • The newly added custom helper method RenderCustomFieldShortInfo calls the created custom field named ShortInfo of type Short text.
  • In the example, the RenderCustomFieldShortInfo method is called both on the root and on the child level.

Sample custom fields of different types

NOTE: When using any of the templates below, you must replace NameOfField with the name of the custom field.

Short text

Long text (text area)

Long text (editor)

Number

Yes/No

Date time

Related image (single)

Related image (multiple)

Related video (single)

Related video (multiple

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?