Skip to main content

Sitecore

Insertion of Sitecore Dictionary Item and Usage

Dictionary Domain

Within Sitecore, Dictionary is something that allows the developer to create a key-value pair. In this blog post, we will look at the different aspects of the dictionary domain concept.
First, what is the key-value pair in Sitecore Dictionary? The key-value pair consists of two related data elements:

  • Key-A constant that defines the data set.
  • Value-A variable that belongs to the set.

Generally, the Dictionary’s key name is hardcoded by the developers within the code of rendering.
Then you may ask, when should you use and when should you not use Dictionary? Dictionary is typically used for labels that are fixed and are to be used on the website, e.g. button text, taglines, etc. Sitecore Dictionaries follow a simple structure and the content author can edit the label. However, Dictionaries are hardcoded in the rendering. In some resources, you may not be able to personalize and test the functionalities for Dictionary resources which is when you should not use it. Overall, Dictionary can be used in the view file directly.

Features of Sitecore Dictionary

Dictionary Domain:

  • In Sitecore, Global dictionaries are available and Global dictionaries can also be created.

Dictionary Localization:

  • Sitecore Dictionary support multiple languages.
  • It uses Sitecore’s native logic for localization.

How to Create Global Dictionary Item in Sitecore

In Sitecore, Dictionary items can be created globally and can be used in the view file. To create Dictionary Item in Sitecore, follow given steps:
1. First, Navigate to /Sitecore/system/Dictionary
Sitecore Dictionary
2. Then, right-click on Dictionary and select Insert–>Dictionary Entry
sitecore dictionary entry
3. Next, inside the created item, fill the fields
fill the fields

  • Key: This value will be used for calling a Dictionary Item in a view.
  • Phrase: This value is the actual value that will be displayed when we call a Dictionary Item.

Sitecore globalization phrase
4. Finally, go to the view file in which you want to use the Dictionary Item and use the following code in the file to access the Global Dictionary Item Phrase using Dictionary Key.
@Sitecore.Globalization.Translate.Text(“Key Name”)

How to Create a Dictionary Item in Content node

Another way to create a site-specific Dictionary item in Sitecore is to create it in the content node. To create Site-specific Dictionary Item in Sitecore, follow given steps:
1. Navigate to the location where you want to create the Dictionary Item.
2. Right-click on the folder and select Insert–>Insert from Template
3. Navigate to select the template (Template/System/Dictionary/Dictionary Entry)
4. Give the Item name as per your requirement.
5. Press Insert to create Item.
6. Inside created item fill the fields

  • Key: – This value will be used to access Dictionary Item in a view.
  • Phrase: -This value is the actual value that will be displayed when we call a Dictionary Item.

7. Create a patch file inside Include Folder to specify Dictionary Domain in the Site Configuration. Paste the GUID of the item in dictionaryDomain attribute like the below image.
<configuration xmlns:patch=”http://www.sitecore.net/xmlconfig/“>
<sitecore>
<sites>
<site name=”website”… dictionaryDomain=“<GUID/PathToDictionary>”/>
</sites>
</sitecore>
</configuration>
 
8. To use the Dictionary item from the current site Go to the View file and use the following code in the file.
@Sitecore.Globalization.Translate.Text (“key”);
*In case if you want to use the dictionary item from a different domain, use:
 @Sitecore.Globalization.Translate.TextByDomain(“Dictionary Domain Name”, key”);

How to Set Dictionary Domain Config in Sitecore SXA

In SXA, we can use the Dictionary Item that can be created and can be used without adding a config file just by changing the site’s definition in SXA. Follow the given steps to create and use Dictionary item in Sitecore SXA:
1. Navigate to the location where you want to create the Dictionary Item.
2. Right-click on the folder and select Insert–>Insert from Template
3. Navigate to select the template (Template/System/Dictionary/Dictionary Entry)
4. Give the Item name as per your requirement.
5. Press Insert to create Item.
6. Inside created item fill the fields

  • Key: – This value will be used for calling a Dictionary Item in a view.
  • Phrase: -This value is the actual value that will be displayed when we call a Dictionary Item.

7. To change the site definition through SXA

  • Go to (sitecore/content/<tenant>/<site>/Settings/Site Grouping/<site>)
  • Find Other Properties and paste the following in the field and insert.

paste other properties
8. To use the Dictionary item from the current site, go to the View file and use the following code in the file.
@Sitecore.Globalization.Translate.Text (“key”);
*In case if you want to use the dictionary item from different domain, use:
 @Sitecore.Globalization.Translate.TextByDomain(“Dictionary Domain Name”, key”);
Hopefully, this blog taught you a little more about how to insert a Dictionary Item and its usage.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Niranjan Sadhu

More from this Author

Categories
Follow Us
TwitterLinkedinFacebookYoutubeInstagram