Creating Custom Dictionary in Sitecore

Why do we need Sitecore Dictionary ?

Every content on a webpage must be editable in Sitecore. This rule applies not only to content that is specific to context items or datasource items, but also to form labels, button texts and other similar content as well.

These pieces of text are used across various pages, hence, it is mostly recommended to keep them as Dictionary entries so that they can be edited from a single place.

For example – In the events listing page in Image-1, there are event tiles which have template Event Detail. The “Read More” button in Image-1 is not specific to the “Events Tile” . You can see it at multiple places on page. So, instead of keeping it as a field in Event Detail template, it is recommended to maintain it as a dictionary entry item.

Image-1 : Events Listing Page with Event Tiles

If sitecore comes with a built-in dictionary, then why create a custom dictionary?

One of the reasons to create custom dictionary is the location of OOTB dictionary in Sitecore. Its path is – /sitecore/system/Dictionary. Since it is present as a descendant of System node, only admin users can access it. To provide flexibility to content authors to modify the dictionary entries, we create custom dictionaries as descendant of “/sitecore/content” node.

Step by Step create your custom dictionary

Step 1 – Login to your sitecore instance and go to Content Editor. Select “/sitecore/content” item and click on “Insert -> Insert from Template” option as shown in Image-2.

Image-2

Step-2 – Choose the “Dictionary Domain” template on path “/sitecore/templates/System/Dictionary/Dictionary Domain” and given a name to your Dictionary (I have used “Global Dictionary” here). Click “OK”. (Refer Image-3)

Image-3

Step-3 (Optional) – Change the icon of your custom dictionary from “Icon” option in “Configure” tab in Sitecore Ribbon. (Refer Image-4)

Image-4

Note – Here, for demonstration purpose , I have created the dictionary folders as per alphabets. Example – Dictionary folder “L” will have dictionary entries with first letter “l”. Also, to establish an easy convention in project, I am naming dictionary entries with small letters without any special character.

Step-4 – Right click Global Dictionary and select Insert->Dictionary Folder. Give it a name as per your project’s guidelines and click “OK”. Here, I have named it “R”. (Refer Image-5)

Image-5

Step-5 – Right click the dictionary folder you just created and select Insert -> Dictionary Entry. Name it as per your project’s guidelines. Here, I have named it “readmore”. Click “OK”. Enter the value of key and phrase field in “readmore” item. (See Image-6)

Image-6 : Global Dictionary with Dictionary Folders and Dictionary entries

Step-6 – Our sitecore dictionary is now ready. But how will sitecore know that it should use this custom “Global Dictionary” domain instead of the OOTB one? For this, we make an entry of “dictionaryDomain” in the site definition of the website. Here, I have EventsSiteDefinition.config patch file for site definition in \Website\App_Config\Include folder. Add “dictionaryDomain” attribute to it. Its value is the item ID of your custom Dictionary “Global Dictionary”. (Refer Image-7)

Image-7

Step -7 (Last Step!) – Go to your view page and replace the static “Read More” text with @Sitecore.Globalization.Translate.Text(“readmore”) . Publish this view to your root folder and your custom dictionary is working!!!!!

Image-8

Leave a comment