Sitecore Item Path Using Display Names

Sitecore Item Path Using Display Names
Photo by Ugne Vasyliute / Unsplash

In Sitecore, the default Paths.FullPath (or ProviderPath in PowerShell) property returns the item's path using item names. If you want a similar path but using display names instead of item names, Sitecore does not provide a direct property for that. However, you can write a custom PowerShell script to generate the path with display names.

Here's a PowerShell function that constructs the path using display names:

function Get-DisplayNamePath {
    param (
        [Sitecore.Data.Items.Item]$item
    )

    $displayNameParts = New-Object 'System.Collections.Generic.List[string]'

    # Traverse up the tree, adding each item's display name to the beginning of the array
    while ($item -ne $null) {
        $displayName = if ($item.DisplayName) { $item.DisplayName } else { $item.Name }
        $displayNameParts.Insert(0, $displayName)
        $item = $item.Parent
    }

    $displayNamePath = $displayNameParts -join "/"
    return $displayNamePath
}