Beautify Sitecore field names

Reading time ~1 minute

Find all fields with incorrect title and fix them to stop users eyes from bleeding.

Introduction

If you create fields without spaces in a name then there is a big chance that you forget about setting its title.

Then users will see something like this:

Not a big deal? Maybe but I am perfectionist and I could not leave it without any action.

Powershell power

Usage

Get template fields without valid title from whole database

1
Get-TemplateFieldWithoutValidTitle

Get template fields without valid title from part of a tree

1
2
$startItem = Get-Item -Path '/sitecore/templates/System/Media/Versioned'
Get-TemplateFieldWithoutValidTitle $startItem

Get template fields without valid title from part of the a and format it

1
2
$startItem = Get-Item -Path '/sitecore/templates/System/Media/Versioned'
Get-TemplateFieldWithoutValidTitle $startItem | Format-Table -Property ID, Name, @{Expression={ Get-Title $_.Name };Label="Suggested Title"}, ItemPath -AutoSize

Example result

ID                                     Name                Suggested Title      ItemPath
--                                     ----                ---------------      --------
{9C6E9C07-FC48-40BA-89CC-A263AAC0C89A} ZipCode             Zip Code             /sitecore/templates/System/Media/Versioned/File/Location/ZipCode
{5A3DEDAA-C9BC-490B-B2A1-C79E0EA83151} CountryCode         Country Code         /sitecore/templates/System/Media/Versioned/File/Location/CountryCode
{24DEF54B-DB0D-4BDC-BF33-DE36A37D5186} LocationDescription Location Description /sitecore/templates/System/Media/Versioned/File/Location/LocationDescription

After you get results you can process items in a loop and set title to suggested title (item name with additional spaces near upper-case letters)

Script source

Get-TemplateFieldWithoutValidTitle.ps1

Summary

I use Powershell almost everyday. Many times I had a situation when I knew that I wrote something but it is gone or hidden somewhere.

That’s why I’ve decided to create a repository with all my scripts (SitecorePowerShellLibrary).

Right now, it’s kinda empty, but collection will grow.

If you follow me on twitter @AlanPloc you are safe, because I am going to link all new scripts there. In case you are not using twitter to follow people you can follow github project or add my blog to your feed reader.

Asset Optimizer configuration

Explanation of different configuration options of SXA Asset Optimizer Continue reading

Items as resources and Unicorn

Published on November 21, 2021

Sitecore Extensions version 3.4 released

Published on November 07, 2020