We all know that with Sitecore we have extensive functionalities we can use when it comes to dictionaries. They can be used to make form labels, button texts, watermarks and other pieces more dynamic rather than hardcoded. They can even support functionality similar to the string.Format() method in .NET. Let’s suppose I have a dictionary item for today’s date:
I can use this like so:
Which will result in something similar to this:
And sure, out of the box these dictionary items aren’t editable, but there are solutions for that.
All in all, dictionaries are pretty useful – and then I saw some cool functionality I wasn’t previously aware of!
If I create a new dictionary entry in my content tree, and the value of the ‘key’ field corresponds with a fieldname for one of my templates, Sitecore will output the value of the ‘phrase’ field in the Content Editor. As an example, if I have a field called ‘logo’ I might want to give a little more information to my content editors when they work with the Content Editor interface. Should it be the company logo? A logo for a specific piece of functionality? Logo of the customers the company has done business with? There’s a lot of different uses for a logo field (granted, some are more valid than others in my example).
Everyone is probably aware of features like help texts that achieve a similar goal, but another option is to create a dictionary item with the same key value as the field name, and some phrase value.
Which then, without having to do anything else, resolves to the following
It still works nicely with the help texts as well of course.
It could end up being a bit bothersome for developers though, because this actually hides the fieldname from the item – so when a developer needs to reference the field in code (by using something like item[“logo”] in our example here) they’ll need to go to the template itself (potentially in the inheritance tab if the field in question comes from an inherited template).
This dictionary item can obviously be translated as well like normal (so create a new version of the item in the language required, then translating the phrase). Keep in mind that this translation won’t show up by changing the language version in the content tree but only by changing the actual interface language.
This can also be achieved by giving the ‘title’ field on the field definition item in the content tree a value. In fact, when the ‘title’ field on the field definition item is set as well as the dictionary item, the ‘title’ of the field definition item ‘wins’.
Don’t want to have your field name translated based on dictionary items? Not to worry, the field definition item also has a checkbox field to do exactly that!
This is a repost of the post I put on the Sagittarius website