0

As the title states I am having problems with this, Utilizing the code Brenden Kehren initally set forth from this thread: https://devnet.kentico.com/questions/kentico-9-how-to-define-language-in-html

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
    if (CurrentDocument != null)
    {          
        CMS.UIControls.ContentPage page= this.Page as CMS.UIControls.ContentPage;
        if (page != null)
        {
            string lang= CMS.Localization.LocalizationContext.CurrentCulture.CultureCode;
            page.XmlNamespace += " lang=\"" + lang + "\"";
            page.XmlNamespace += " xml:lang=\"" + lang + "\"";
        }
    }
}
</script>

however for the life of me I cannot seem to get it to work, keep on getting: Uncaught SyntaxError: Unexpected token void

At the line: protected void Page_Load(object sender, EventArgs e)

I have placed the code in the header of the master template, I open the Header Tab, And in the text box under where it says "Add HEAD element content:" I paste in the full snippet that was provided. Including the . Running Kentico 9 if that helps.

It just seems odd that I cannot get this to work. Any suggestions?

The site is multi cultural with an English and Spanish version, I thought Kentico was able to auto set up the Language tag in that case but apparently not.

3 Answers 3

1

It should be in the layout (where all your zones are), i.e. after the body tag. Secondly CultureCode depends on your URL, your url must contain culture code.

1
  • URL does contain the culture code, i.e. colorado.quitlogix.org/en-US I have tried placing the code in the body as well, but still get the error.
    – Dan Main
    Sep 7, 2018 at 18:40
0

If you place the script directly in the layout like this:

script code in kentico

It should have the following output: (before and after html)

added language tags in html

1
  • Cool, I will try that.
    – Dan Main
    Sep 11, 2018 at 21:40
-1

This code should go in code behind. Layout need to used for this in code behind section. If you add in HTML segment, browser will not understand this code.

1

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.