Discussing programming techniques can be like discussing religion and politics. There might never really be a correct answer, but everyone thinks they know it. In the case of rendering labels (first name, last name, address for example) in #Sitecore we have more than a few options. In my example I have a label called Introduction. I have three different ways to render this field on the site.
The first line uses the Sitecore dictionary. The second is set in the controller from a settings page and the third line is coming from the home page item.
@Translate.Text("homeintrolabel") @Model.IntroText @Model.HomePage.Fields["Intro Text Label"].Value
They all render the same. As you can see below.However which way is the best way to do it?
I prefer using the dictionary to do it. It is quick and easy to render a field that way. I worked for one company that only used a settings item or the content item. Another company I worked for preferred the dictionary. So which way do you prefer?
4 thoughts on “#Sitecore and field labels. So many options to render them, but what is the best option?”
If the labels should not be edited in the Experience editor and especially if they are reused, definitely Dictionary. In other cases a standard text field might work better. Trying to avoid religion. 🙂
Excellent point. Always have to remember to make sure it works with Experience Editor. At one company I was at I tried hard to get them to use the Dictionary for some things, but they did not want to change their ways. 🙂
I prefer a template based labels item with custom attribute to decorate my model properties. Made this to also work in experience editor. Benefit is that I can differentiate the labels based on datasource and therefor can personalize and a/b test the labels. Dictionary items can also easily be made to be editable in experience editor but do not easily support personalization and/or a/b tests.
LikeLiked by 1 person
Great points and ideas! Thanks for sharing.