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

How to display a property in all the existing language versions on the same page?

Vote:
 
Hello, I'm trying to display the following link to a pdf in all language versions on the same page. This pdf property is unique per language. Also available in: English Français Español I can't seem to be able to extract the correct value in the French or the Spanish. I keep getting the English one instead. I'm not sure what is wrong in the code below. Any help would be greatly appreciated. public string GetPDFLink() { //private PageData langPage; This is declared elsewhere. LanguageBranch lb = LanguageBranch.Load(DocumentPage.LanguageBranch); string _getPDFLink = ""; if (lb.Name == "Default") { _getPDFLink = (string)DocumentPage["varFilePath"]; } else if (lb.Name == "FR") { EPiServer.Core.LanguageSelector selectorFR = new EPiServer.Core.LanguageSelector("FR"); langPage = EPiServer.Global.EPDataFactory.GetPage(DocumentPage.PageLink, selectorFR); _getPDFLink = (string)langPage["varFilePath"]; // This should be the value from the French version of the page } else if (lb.Name == "ES") { EPiServer.Core.LanguageSelector selectorES = new EPiServer.Core.LanguageSelector("ES"); langPage = EPiServer.Global.EPDataFactory.GetPage(DocumentPage.PageLink, selectorES); _getPDFLink = (string)langPage["varFilePath"]; // This should be the value from the Spanish version of the page } return _getPDFLink; }
#13279
Nov 26, 2007 11:47
Vote:
 
If the link to the pdf is stored in a property (varFilePath) you should use the DataFactory.GetLanguageBranches method instead of the LanguageBranch class to get the available language versions. Here is some code to get you on the track: // Only brain compiled - put it into PageLoad PageDataCollection langVersions = Global.EPDataFactory.GetLanguageBranches(CurrentPage.PageLink); PageDataCollection pagesWithPdfLinks = new PageDataCollection(); foreach (PageData page in langVersions) { // Check that it is not the same lang as the currently loaded one // Also check that the page has a value for the pdf link if (CurrentPage.LanguageBranch != page.LanguageBranch && page["varFilePath"] != null) { // We have a language version of the page pagesWithPdfLinks.Add(page); } } lstPdfLinks.DataSource = pagesWithPdfLinks; lstPdfLinks.DataBind(); Now you have a collection of page language versions that have a value for the pdf link. It does not contain the currently showing language version. It has been bound to a PageList control, which could look like this: Also available in:  ]]>  and you need the GetLanguageDisplayName method in your code behind file: protected string GetLanguageDisplayName(string languageBranch) { return LanguageBranch.Load(languageBranch).Name; } I think this should do the trick, at least it should give you some pointers on how to solve it. /Steve
#15567
Nov 26, 2007 21:30
Vote:
 
Thank you Steve. This worked great. Now, I will use this same function for a NewsList control where each of the Items iterated will display this same function. It will look something like this. ---------------------------------------------- PageName Also available in: English French Spanish ---------------------------------------------- PageName Also available in: English French Spanish ---------------------------------------------- PageName Also available in: English French Spanish ---------------------------------------------- How would you apply the function you indicated? I tried the following in the ascx: ]]>" runat="server"> <%#ContainerPage(Container.CurrentPage)%> <%----%> <%# GetLanguageDisplayName(Container.CurrentPage.LanguageBranch) %> <%----%>   And the following in the cs: public PageDataCollection pagesWithPdfLinks = new PageDataCollection(); public PageDataCollection langVersions; protected EPiServer.WebControls.PageList lstPdfLinks; public void ContainerPage(PageData pr) { langVersions = Global.EPDataFactory.GetLanguageBranches(pr.PageLink); foreach (PageData page in langVersions) { // We have a language version of the page pagesWithPdfLinks.Add(page); } lstPdfLinks.DataSource = pagesWithPdfLinks; lstPdfLinks.DataBind(); } protected static string GetLanguageDisplayName(string languageBranch) { if (LanguageBranch.Load(languageBranch).Name == "Default") return "English"; else return LanguageBranch.Load(languageBranch).Name; } Needless to say, it doesn't work as smoothly as the one you suggested. Any advice?
#15568
Nov 28, 2007 18:18
Vote:
 
I've asked this question on a separate string. http://www.episerver.com/en/EPiServer_Knowledge_Center/Developer-Forum2/EPiServer-Developer-Forums-/1805/14444/
#15569
Nov 29, 2007 17:03
* 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.