Search code examples
sitecorefieldsitecore8

In Sitecore 8 can I get a field value in the language version of the page


I want to get a field value in the language version of the page. For example I have an item called Search Placeholder in en-us with the the field value "Select.." on the en-us page it shows that value. But using the code below when I create Search Placeholder in en-gb and I put in the value "Select2..." It shows up blank on the en-gb page.

string fieldName = "Search Placeholder Text";
Sitecore.Data.Items.Item someItem = Sitecore.Context.Database.GetItem("/sitecore/content/site/shared-content/Search Placeholder");
Sitecore.Data.Fields.Field someField = someItem.Fields[fieldName]; 
string searchPlace = someField.Value;

Is there a way to check if Search Placeholder has a language version for a page?


Solution

  • First of all, you can pass chosen language to GetItem method:

    Sitecore.Context.Database.GetItem(path, language)
    

    Then you can check if item has any version in that language using:

    someItem.Versions.Count > 0
    

    If item has more than 0 versions and the field is null it means that either this item has not been publish after field was added to the template or the field item itself has not been published.