TagHelper

The `UmbnavitemTagHelper` can be extended to customize how menu items are rendered in Razor views.

Basic Extension

using Microsoft.AspNetCore.Razor.TagHelpers;
using Umbraco.Community.UmbNav.Core.TagHelpers;

[HtmlTargetElement("custom-umbnavitem")]
public class CustomUmbNavItemTagHelper : UmbnavitemTagHelper
{
    // Your customizations here
}

Override Points

GetTagName

Control which HTML tag is rendered:

protected override string GetTagName()
{
    // Use <button> for certain items
    if (MenuItem.CustomClasses?.Contains("button") == true)
    {
        return "button";
    }

    return base.GetTagName();
}

GetContent

Customize the text content:

GetUrl

Customize URL generation:

IsItemActive

Customize active state detection:

Customize the href attribute:

ProcessClasses

Customize CSS class output:

ProcessActiveState

Customize active class application:

ProcessTarget

Customize target attribute:

ProcessRel

Customize rel attribute:

ProcessCustomAttributes

Add any custom attributes:

Complete Example: Bootstrap 5 TagHelper

Usage:

Complete Example: Accessible TagHelper

Complete Example: Analytics TagHelper

Properties Reference

Available Properties

Property
Type
Description

MenuItem

UmbNavItem

The menu item being rendered

Mode

UrlMode

URL generation mode

Culture

string?

Culture for URLs

LabelTagName

string

Tag for label items

ActiveClass

string?

Class for active state

IsActiveAncestorCheck

bool

Check ancestors

CurrentPage

IPublishedContent?

Current page

IsLabel

bool

Whether item is a label

Protected Members

Member
Type
Description

IsLabel

bool

Check if item is a label

Usage in Views

Register your custom TagHelper in _ViewImports.cshtml:

Then use it:

Last updated

Was this helpful?