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));
David
Hi,
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)); {Castle.Proxies.TeaserBlockProxy} [Castle.Proxies.TeaserBlockProxy]: {Castle.Proxies.TeaserBlockProxy} ContentGuid: {a7568823-0c9e-46fa-b707-d07729ccdb9c} ContentLink: {61} ContentTypeID: 12 IsDeleted: false Name: "Customer testimonial wide teaser" ParentLink: {60} var foo = teaserBlock as ILocalizable; {Castle.Proxies.TeaserBlockProxy} [Castle.Proxies.TeaserBlockProxy]: {Castle.Proxies.TeaserBlockProxy} ExistingLanguages: Count = 2 MasterLanguage: {en} var langs = foo.ExistingLanguages; Count = 2 [0]: {en} [1]: {sv}
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.
//Mathias
Hi,
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.
//Jonny
Hi,
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 sourceContentIlocalizable = sourceContent as ILocalizable;
var langs = sourceContentIlocalizable.ExistingLanguages;
Is it a bug or am I doing something wrong?
//Jonny