Reputation: 4100
I have an Item in sitecore with id '{05B1C498-39D1-40D6-B454-2A3277A6DDF9}
' which has one language version in "en
" and one in "da-DK
" .
For this Item there is a field "Test
" with type text
, In English version I have saved "English Text" in this field. And for Danish version of above item I have saved "Danish Text" in the field "Test
".
I want to get the the above item in Danish language. I used this code:
string dicItemId= "{05B1C498-39D1-40D6-B454-2A3277A6DDF9}"
Item dictionaryItem = Context.Database.GetItem(dicItemId, Sitecore.Data.Managers.LanguageManager.GetLanguage("da-DK"));
lblTest.Text = dictionaryItem["Test"];
I am expecting to see the string "Danish Text" for the above label. But somehow its not getting the Danish version and output is "English Text".
I also tried to get the version of above item in a language whose version does not exist in my Sitecore, I tried with:
Item dictionaryItem = Context.Database.GetItem(dicItemId, Sitecore.Data.Managers.LanguageManager.GetLanguage("nl-NL"));
I was expecting the dictionaryItem
as null
but still it contains the item with id '{05B1C498-39D1-40D6-B454-2A3277A6DDF9}
'
Upvotes: 0
Views: 609
Reputation: 328
To troubleshoot, try the following steps:
Context.Database.GetItem(..) will always return the Item (provided it exists), even when it does not include a specific language version.
Try the following simple test to ensure the item in your language is published:
Upvotes: 0