Menu Builder Service

The `IUmbNavMenuBuilderService` processes raw menu data from the property editor, resolving content, filtering items, and applying build options. Understanding this service is key to advanced UmbNav u

Overview

The Menu Builder Service is responsible for:

  1. Content Resolution - Converting content keys to IPublishedContent

  2. Image Resolution - Loading media items for menu images

  3. Visibility Filtering - Hiding items based on authentication status

  4. Active State Detection - Marking the current page and ancestors

  5. Option Application - Applying UmbNavBuildOptions transformations

  6. Child Processing - Auto-expanding children from content nodes

  7. Depth Limiting - Enforcing maximum nesting depth

Automatic Processing

When you call Model.Value<IEnumerable<UmbNavItem>>(), the built-in value converter automatically calls the Menu Builder Service. You typically don't need to call it manually.

However, for advanced scenarios, you can inject and use the service directly.

Manual Usage

Injecting the Service

@inject IUmbNavMenuBuilderService MenuBuilder

Or in a controller/service:

Basic Usage

With Build Options

Build Options Reference

The UmbNavBuildOptions class controls how the service processes items:

Option
Effect

RemoveNoopener

Sets Noopener to null on all items

RemoveNoreferrer

Sets Noreferrer to null on all items

HideIncludeChildren

Ignores the "Include Child Nodes" setting

RemoveDescription

Sets Description to null on all items

RemoveCustomClasses

Sets CustomClasses to null on all items

RemoveImages

Sets Image and ImageArray to null

MaxDepth

Limits nesting depth (0 = unlimited)

Processing Pipeline

The service processes items through these stages:

Practical Examples

Filtered Navigation

Create a navigation that only shows certain item types:

Different Depths for Different Views

Stripping Data for JSON API

Caching Processed Menus

Service Interface

Extending the Service

You can replace the service with a custom implementation. See Extending the Menu Builder Service for detailed guidance.

Quick example:

Register with:

Delivery API Support

The service automatically supports Umbraco's Content Delivery API. When items are requested through the Delivery API, the UmbNavValueConverter uses the same Menu Builder Service with options derived from the Data Type configuration.

Performance Considerations

  1. Content Resolution - The service looks up content by GUID, which is fast with Umbraco's caching

  2. Recursive Processing - Deep nesting increases processing time; use MaxDepth to limit

  3. Authentication Check - Uses HttpContext.User, which is lightweight

  4. Caching - Consider caching processed results for high-traffic sites

Error Handling

The service handles common error cases:

  • Missing Content - Items with unresolvable content keys are excluded

  • Unpublished Content - Unpublished content items are excluded

  • Null Items - Empty or null collections return empty results

  • Invalid Options - Null options default to UmbNavBuildOptions.Default

Errors are logged but don't throw exceptions, ensuring navigation degrades gracefully.

Last updated

Was this helpful?