UmbNavItem

The `UmbNavItem` class is the core data model representing a menu item in UmbNav. Understanding this model is essential for working with UmbNav in views and extensions.

Class Definition

namespace Umbraco.Community.UmbNav.Core.Models;

public class UmbNavItem
{
    public Guid Key { get; set; }
    public required string Name { get; set; }
    public string? Description { get; set; }
    public string? Url { get; set; }
    public string? Icon { get; set; }
    public UmbNavItemType ItemType { get; set; }
    public Guid? ContentKey { get; set; }
    public string? Anchor { get; set; }
    public bool Published { get; set; }
    public IEnumerable<UmbNavItem>? Children { get; set; }
    public IPublishedContent? Content { get; set; }
    public int Level { get; set; }
    public string? Target { get; set; }
    public ImageItem[]? ImageArray { get; set; }
    public IPublishedContent? Image { get; set; }
    public string? CustomClasses { get; set; }
    public bool IsActive { get; set; }
    public bool HideLoggedIn { get; set; }
    public bool HideLoggedOut { get; set; }
    public string? Noopener { get; set; }
    public string? Noreferrer { get; set; }
    public bool IncludeChildNodes { get; set; }
}

Properties Reference

Identification

Property
Type
Description

Key

Guid

Unique identifier for this menu item

Name

string

Display name (required)

Description

string?

Optional description text

Icon

string?

Icon name (e.g., "icon-document")

Item Type

Property
Type
Description

ItemType

UmbNavItemType

The type of menu item

URL & Navigation

Property
Type
Description

Url

string?

The URL (for Link items) or resolved URL (for Document items)

ContentKey

Guid?

Umbraco content GUID (for Document items)

Anchor

string?

URL anchor/fragment (e.g., "#section")

Target

string?

Link target (e.g., "_blank")

Content Resolution

Property
Type
Description

Content

IPublishedContent?

Resolved content node (populated by Menu Builder Service)

Published

bool

Whether the linked content is published

Hierarchy

Property
Type
Description

Children

IEnumerable<UmbNavItem>?

Child menu items

Level

int

Nesting level (0 = root)

IncludeChildNodes

bool

Auto-include content children when rendering

Images

Property
Type
Description

ImageArray

ImageItem[]?

Raw image data from the editor

Image

IPublishedContent?

Resolved image media (populated by Menu Builder Service)

Styling

Property
Type
Description

CustomClasses

string?

Custom CSS classes

IsActive

bool

Whether this item is the current page

Visibility

Property
Type
Description

HideLoggedIn

bool

Hide when user is authenticated

HideLoggedOut

bool

Hide when user is not authenticated

Property
Type
Description

Noopener

string?

Value for rel="noopener"

Noreferrer

string?

Value for rel="noreferrer"

JSON Serialization

The model is designed for JSON serialization with explicit property names:

Working with Different Item Types

Document Items

Content-linked items with resolved URLs:

External or custom URLs:

Title/Label Items

Non-clickable text:

Checking Item Properties

Has Children

Has Image

Is Published Content

Has Custom Classes

Hierarchy Navigation

Recursive Rendering

Flattening the Tree

ImageItem Model

The ImageItem class represents image data before resolution:

TypeScript Equivalent

In the frontend, the model is represented as ModelEntryType:

Best Practices

1. Always Null-Check Optional Properties

2. Use Extension Methods for URLs

3. Check ItemType Before Accessing Type-Specific Properties

4. Consider Unpublished Items

Last updated

Was this helpful?