How to define language attribute in <html> tag in kentico 9.

Karambir Sharma asked on September 7, 2017 12:50

How to define language attribute in

Correct Answer

Brenden Kehren answered on September 7, 2017 13:15

You can add this in your main master page layout.

<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 + "\"";
            }
        }
    }
</script>
2 votesVote for this answer Unmark Correct answer

Recent Answers


Chetan Sharma answered on September 7, 2017 13:18 (last edited on September 7, 2017 13:18)

Brenden's answer is spot on. I will also add this line because sometime some of the tools give this error unless this tag is defined too.

page.XmlNamespace += " xml:lang=\"" + lang + "\"";

2 votesVote for this answer Mark as a Correct answer

Karambir Sharma answered on September 7, 2017 13:37

Thanks Brenden and chetan for the answer.

0 votesVote for this answer Mark as a Correct answer

Esme Allen-Creighton answered on July 25, 2018 23:40

Hi Everyone,

I've used the code above In my master page layout. It's rendering the lang attributes perfectly when I inspect the page, but when I run it through a validator, and on view page source, I'm getting a duplication of lang="en-CA". Any thoughts?

0 votesVote for this answer Mark as a Correct answer

Daniel Main answered on September 5, 2018 19:41

Not sure where the problem is I added this code and it is giving the error:

Uncaught SyntaxError: Unexpected token void

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

Any ideas?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.