Sitecore CMS also uses the Sitecore Dictionary

Something I was reminded of today, Sitecore will also use the Dictionary that you define in the CMS šŸ™‚

Let’s do a quick demonstration. Say you have a Page Template called My Details:

My Details Page Template

Then, add this to the Insert Options of a particular item, say the Home item.Ā If you right-click on the item in your content treeĀ and select Insert, it will display your “My Details” page template as an option:

My Details Insert Options

Now, say there is a requirement to translate/manage the string for aĀ navigation item on the website, more specifically the My Details navigation item and you wanted to change this to My User Area. One way of doing this is to add a dictionary definition for this and reference this dictionary definition in your code:

My User Area definition

Now go back to the Home Page and right-click to add a new child item. You will see that Sitecore has identified that there is a dictionary definition for “My Details” and is using this instead of your template name.

My User Area Insert Options

Be mindful of this, sometimes this may be unintended. however if you wanted to translate aspects of the Sitecore CMS, then this would be a great place to do this šŸ™‚

Which Sitecore Index to use?

I was asked an interesting question the other day:

Why are my components not working in the Page Editor?

This puzzled me for a bit, the Page Editor was not preventing editing of the content, however the content was not being saved back into Sitecore. However, if the content was modified directly in the Content Editor, everything was fine.

So, what was going on?

Upon closer inspection of the code, it appeared that a the Sitecore ContentSearch was being used to pull content from the Index – but the index being used was “sitecore_web_index”.

ISearchIndex searchIndex = Sitecore.ContentSearch.ContentSearchManager.GetIndex("sitecore_web_index");

When this happens, creating a SearchContext, performing a searchĀ andĀ calling GetItem() on a SearchResultItem will pull the item out of the Web database. This is fine, however as the items are coming from the Web database, this will not play nicely with the Page Editor.

A “quick ‘n’ dirty” method of getting aroundĀ this is to look at the Context database to see whether you should be using the Master index or Web index. Below is a static helper to decide which index you should be looking at:

public static string GetIndex()
    // TODO - Find a way of getting the database associated with the Datasource
    switch (Sitecore.Context.Database.Name)
        case ("master"):
            return "sitecore_master_index";
            return "sitecore_web_index";

Then, simply use this static function in your code instead of naming the index directly:

ISearchIndex searchIndex = Sitecore.ContentSearch.ContentSearchManager.GetIndex(SitecoreJim.Utilities.Index.GetIndex());

Yes, this is quick and dirty – just wanted to get this out there to help others, however you get the concept šŸ™‚

Upon doing a quick google search, I also found this post by The Grumpy Coder which discusses the same thing.

Hope this helps someone!