November Happy Hour will be moved to Thursday December 5th.

GetLanguageBranches on block

Vote:
 

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 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?

//Jonny

#119522
Mar 28, 2015 22:35
Vote:
 

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

#119524
Edited, Mar 28, 2015 23:50
Vote:
 

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

#119525
Edited, Mar 29, 2015 0:30
Vote:
 

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

#119535
Mar 29, 2015 21:57
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.