When I try to get languagebranches for a block I only retrive the masterlanguage for the block even if the block exist in other language.
I've tried IContent and ILocalizable with no luck.
var contentLink = new ContentReference(12);
var sourceContent = Locate.ContentRepository().Get<>IContent>(contentLink);>
var sourceContentIlocalizable = sourceContent as ILocalizable;
var langs = sourceContentIlocalizable.ExistingLanguages;
Is it a bug or am I doing something wrong?
This should do the trick and get all language versions of the block:
IContentRepository repo = ServiceLocator.Current.GetInstance<IContentRepository>();
var allLangVersions = repo.GetLanguageBranches<TeaserBlock>(new ContentReference(90));
I tried the following in the immediate window while debugging EPiServer's Alloy MVC template site; ID=61 belongs to a teaser block.
var teaserBlock = ServiceLocator.Current.GetInstance<IContentLoader>().Get<IContent>(new ContentReference(61));
Name: "Customer testimonial wide teaser"
var foo = teaserBlock as ILocalizable;
ExistingLanguages: Count = 2
var langs = foo.ExistingLanguages;
Count = 2
The English version is master, and the Swedish one is not published, only translated and saved. I also get the same using IContentRepository instead of IContentLoader.
Thank you for your answers. Problem for me is that I use this code: http://cjsharp.com/blog/2013/04/19/automatically-populating-page-or-block-type-properties-for-a-language-branch-in-episerver-7/
When I use your code Mathias:
var teaserBlock = ServiceLocator.Current.GetInstance<IContentLoader>().Get<IContent>(new ContentReference(sourceContent.ContentLink.ID));var foo = teaserBlock as ILocalizable;var langs = foo.ExistingLanguages;
I just get the MasterLanguage. I guess there is something I miss or not understand but I cant seem to find it.
Hope you can help me, thanks in advance.