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

Multiple Language StartPage, how to retrieve the values?

Vote:
 

Hello, Im currently developing a website based on EPiServer CMS 6 r2 and are trying to access the values stored in Language Overview (Editmode -> StartPage -> Language Overview). I am curious about what the best way is to approach this, since i basicly just want the appropriate values for each language, i.e Norwegian, English and Swedish if a StartPage exists for these languages. 

I've tried searching for an example that uses a repeater and hyperlink with the appropriate codebehind included, but i've had no luck so far. Im new to development, episerver and coding overall, so please excuse any mistakes. Thanks for your help!

 

ps. im using a javascript with jquery to create my dropdown menu.

#53432
Sep 08, 2011 16:39
Vote:
 

Hi Robin

If you want to create a dropdown that changes the languages based on what the user chooses take a look at the Alloy Demo templates.

The code looks something like this:

<asp:DropDownList runat="server" ID="LanguageList"  Visible="false" AutoPostBack="true" OnSelectedIndexChanged="ChangeLanguage">
    <asp:ListItem Text="Other languages" Value="noLangSelected" />
</asp:DropDownList>

 

/// <summary>
        /// Initializes the language link.
        /// Checks the number of available and enabled languages. If more than two, 
        /// populates a dropdown-menu with the available and enabled languages.
        /// Otherwise sets the link to the not currently active language.
        /// </summary>
        private void SetLanguage()
        {
            PageDataCollection languageBranches = DataFactory.Instance.GetLanguageBranches(CurrentPage.PageLink);
            //Filter so pages with Replacement language is filtered away.
            new FilterReplacementLanguage().Filter(languageBranches);

            if (languageBranches.Count > 2)
            {
                LanguageList.Visible = LanguageListLabel.Visible = LanguageButton.Visible = LanguageList.Parent.Visible = true;
                foreach (PageData languageBranch in languageBranches.Where(p => p.LanguageID != CurrentPage.LanguageID && LanguageBranch.Load(p.LanguageID).Enabled))
                {
                    LanguageList.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(languageBranch.LanguageID).NativeName, languageBranch.LanguageID));
                }
            }
            else
            {
                foreach (PageData languageBranch in languageBranches.Where(p => p.LanguageID != CurrentPage.LanguageID && LanguageBranch.Load(p.LanguageID).Enabled))
                {
                    Language.Visible = Language.Parent.Visible = true;
                    Language.NavigateUrl = EPiServer.UriSupport.AddLanguageSelection(languageBranch.LinkURL, languageBranch.LanguageID);
                    Language.Text = Translate(new CultureInfo(languageBranch.LanguageID).NativeName);
                    break;
                }
            }
        }

        /// <summary>
        /// Redirects to the selected language.
        /// </summary>
        public void ChangeLanguage(object sender, EventArgs e)
        {
            if (LanguageList.SelectedValue != "noLangSelected")
            {
                Response.Redirect(EPiServer.UriSupport.AddLanguageSelection(CurrentPage.LinkURL, LanguageList.SelectedValue));
            }
        }

Hope this helps

Frederik

#53447
Sep 08, 2011 18:36
Vote:
 

Thanks Fredrik!

#53471
Sep 09, 2011 11:21
Vote:
 
#53696
Edited, Sep 20, 2011 17:26
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.