I am facing Site-improve accessibility error that my page doesn't have a "lang tag" defined. How can I accomplish this in Kentico?
2 Answers
There are possibly two ways to achieve this. One is through C# .NET code in Kentico and the other is through Javascript code. I'm providing you both solutions
In order to fix this problem you have fix two tags for your tool to stop pointing accessibility error. You have to set both "lang" as well as "xml:lang" tag. One way to achieve this through pure Javascript is below. I am proposing this solution as it is independent of any platform.
(function() {
document.getElementsByTagName('html')[0].setAttribute('lang', 'en-US');
document.getElementsByTagName('html')[0].setAttribute('xml:lang','en-US');
})();
You may replace 'en' with language of your choice to correctly point the correct language in place
In Kentico you may achieve this by placing this code in your master template so that these tags can be added on all pages.
In your Kentico master template just add a Head HTML web part and put this code inside it.
<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>
This should fix everything for you.
The recommended way is to open ~/CMSPages/PortalTemplate.aspx web form and edit the lang attribute manually just as you see fit.
Please note that generally speaking the modification of Kentico system files is not recommended, but in this case it is the best way to go. Just keep in mind to document all changes you make.
Edit:
Other solution which does not involve any customization is to use CMSPortalTemplatePage web.config key to set up path to a custom PortalTemplate file. This way you can clone Kentico's PortalTemplate.aspx, make modification in this cloned file and keep the original.
Possible usage:
<add key="CMSPortalTemplatePage" value="~/CMSPages/CustomPortalTemplate.aspx" />
-
1Kentico does not recommend editing base files at all (I'd expect out of all people, you'd know this already). The standard and recommended approach is to clone the file(s) and create your own customizations within those customized files. Knowing this is a base file which all portal pages utilize, the solution Chetan provided is one of the better approaches and doesn't involve customizing base code files. Sep 12, 2016 at 1:55
-
1Yeah, I agree and that is why I mentioned that in my answer :) The solution from Chetan works and it is good that it is mentioned, but it is less efficient so I wanted to provide with an alternative. Sometimes you might be better off customizing system files if you know what you are doing and document everything you do. I've updated the answer with even better solution that doesn't require any customization at all :-)– EnnSep 12, 2016 at 7:14