Jeremy Davis
Jeremy Davis
Sitecore, C# and web development
Article printed from: https://blog.jermdavis.dev/posts/2024/avoid-display-name-confusion

Avoiding Display Name confusion

A trick to rememeber in Content Editor

Published 17 June 2024
Sitecore ~2 min. read

I had a moment of frustration recently, when I spent a while looking for a Data Template in a particular Sitecore site and couldn't find it because a previous developer had set a Display Name. As a result of moaning about this Corey Smith reminded me of a way I could have helped myself here, and it seemed like something to share...

The issue

I was debugging an issue in the startup of a developer instance of a client site. In this particular setup something had gone wrong, and rather than starting up normally the site was failing with a NullReferenceException. When I dug into the code, the place it was failing was processing the value of a particular content field.

My first thought was to got and check that field and verify that it was present and correctly configured, so I browsed the content tree looking for the particular Data Template mentioned in the code. For the sake of an example, lets say it was called ImportantDataTemplate. And when I went to the relevant bit of the content tree, I couldn't see this template at all:

A fragment of content tree, showing a folder containing Data Templates - none of which appear to be the one I'm looking for

I compared this with the QA instance, and that didn't have it either. That confused me a lot, as QA was running ok. I couldn't see how that instance could run at all if it had the same problem as the dev instance?

So I wasted a chunk of time scratching my head in confusion, before having an epiphany: The template was there, but at some point in the past, someone had set a Display Name on it which didn't match the item name:

The Quick Info section of the Content Editor showing the Item Name I had been looking for, but that it had a Display Name set to something else

And that's why I'd not been able to find the template - I was looking for one name (from the code), but it was showing up in the tree with something unrelated.

I may have uttered a few choice words when I realised this...

The fix

Venting to Corey, he reminded me that hiding in Sitecore's Content Editor UI there's a setting which lets you disable the use of Display Names entirely. And sometimes as a developer that's useful. Especially in the situation where a site has been built with Display Names on data templates, and you want to be able to browse the tree with the original names.

The setting isn't necessarily where you't think to look though. When I think "change the way the Content Editor UI displays data" I tend to go to the View ribbon's options:

Sitecore's Content Editor View ribbon, showing the set of checkbox view options like raw values, standard fields and hidden items

But there's nothing there which helps - even "Raw Values", which you might think would do this based on what it does to individual fields.

The real answer is hiding in the burger menu for the Content Editor window. There's an "Application Options" entry hiding there:

The burger menu expanded in Content Editor, showing the Application Options entry

That pops up a window which has a "View" tab. And under there is a radio button for using "Item Name" for the content tree:

The Application Options dialog's View tab, showing the radio button options for showing Display Name and Item Key

And once you've selected that, any item in the content tree that has a Display Name will be shown using its Item Name instead - so it'll match up with any programatic access by name that may be in your code.

Note that when you turn this on your Display Names aren't lost (the field and its value are still on your item) but as well as not showing them in the content tree, it no longer shows the Display Name override value in the Quick Info section of the Content Editor. But clicking the "Display Name" button in the Home ribbon still shows the value from the database:

The Quick Info section of Content Editor again, showing that after the Display Names are turned off they are not shown here, alongside the Display Name dialog showing the value is still present even if it's not shown.

If you compare that to the equivalent screen grab above with the setting off, you'll notice that it doesn't show the presence of a Display Name at all in the Quick Info section. Remember that - it might cause confusion itself.

Conclusion

This is a fairly obscure Content Editor feature - but a useful one none the less. One to file away in the back of your mind for those occasions when it will help. And I should think about "Display Names" more often - if I'd considered that earlier in this process it would have saved me wasting a chunk of time.

But maybe think hard before you set Display Names on Data Templates? Do you really need to do that?

↑ Back to top