2

How do you edit the HTML tag in a Kentico CMS Masterpage, i.e. to add a class attribute?

Currently I have this:

Kentico masterpage html tag

But I want:

<!DOCTYPE html>
<html class="myClass">
  <head>
    <title>

From the screenshot you can see that the HTML tag is not editable.

Is there a way to edit the html tag or tell Kentico to write a class attribute to the html tag?

Dave Haigh
  • 4,369
  • 5
  • 34
  • 56

3 Answers3

1

I have found one solution:

I manually added a class attribute to the HTML tag in this file:-

<solution>/CMSPages/PortalTemplate.aspx

Dave Haigh
  • 4,369
  • 5
  • 34
  • 56
  • this is the only solution I have found so far. – Dave Haigh Jun 01 '12 at 14:19
  • Unfortunately, this solution is a horrible one. Modifying base code isn't a preferred method at all. Try adding some custom code in to an output filter or even in a template where you can modify the body tag like in this post: http://devnet.kentico.com/questions/use-page-template-name-as-a-class-in-the-ascx-master-template – Brenden Kehren Dec 22 '16 at 17:53
1

You can also use the "Head HTML" web part on your page template(s).

jurajo
  • 11
  • 1
  • 1
    I can edit the html tag in the HEAD HTML web part? can you provide a little more detail of how I do this please. – Dave Haigh May 30 '12 at 10:33
1

It is quite disappointing that Kentico still does not support this out of the box. A request to be able to modify the <html> tag directly from code has been filed: http://ideas.kentico.com/forums/239189-kentico-product-ideas/suggestions/5947264-ability-to-modify-page-head-section-and-html-tag In the meantime use the following solutions:

Portal Engine

I solved this the following way, based on Dave Haigh suggestion. In the file /CMSPages/PortalTemplate.aspx change the following line:

<html xmlns="http://www.w3.org/1999/xhtml" <%=XmlNamespace%>
    lang="<%=CMSContext.PreferredCultureCode%>">

ASPX Engine

In your master page, add the following snippet to your code behind file:

<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>

Source: http://devnet.kentico.com/questions/kentico-9-how-to-define-language-in-html

Community
  • 1
  • 1
CodeZombie
  • 5,367
  • 3
  • 30
  • 37
  • Is there a solution for sites that store all of their code in the database? I don't have access to the code for the custom Master page we're using. – Janet Aug 13 '19 at 14:26
  • @Janet Unfortunately I cannot help you on this as I stop working with Kentico. – CodeZombie Aug 13 '19 at 14:58