kenticokentico-11

Can I make the Doctype on a master page (Kentico 11 Portal Engine) dynamic based on a macro?


I've inherited a Kentico 11 site that uses a doctype of

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

The client wants to create AMP variants of their pages using Kentico's AMP module, which uses a subdomain for any AMP content. The module also includes a boolean macro {% AmpFilter.IsAmpPage() %} that tests if you're currently serving AMP content. https://github.com/Kentico/kentico-amp

The issue I'm running into is that AMP seems to want a doctype of

<!doctype html>

. I don't want to change the doctype of the existing site, but it also doesn't look like I can evaluate macros within the master page template's doctype field.

Wondering if anyone has come up against an issue like this; if there's a way to allow macros to be evaluated in the doctype field, or some other approach I haven't thought of.


Solution

  • There's a similar issue when adding the HTML lang attribute to support WCAG 2.0 guidelines. However, the HTML attribute is controlled by a system file PortalTemplate.aspx, which uses the Kentico page's XmlNamespace property. To solve this, we added server-side code in to the master page's layout properties. However, this could also be done in a web part that you add to the master page. Then, instead of changing the page's XmlNamespace property, you would change the page's DocType property, based on whatever conditions you choose. Would this meet your needs?

    <script runat="server"> 
    /// Add Page_Load just to insert the "lang" attribute required by WCAG 2.0 Level A guidelines
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CurrentDocument != null)
        {          
            CMS.UIControls.ContentPage page= this.Page as CMS.UIControls.ContentPage;
            if (page != null)
            {
                System.Globalization.CultureInfo c= new System.Globalization.CultureInfo(CMS.Localization.LocalizationContext.CurrentCulture.CultureCode);
                string lang= c.TwoLetterISOLanguageName;
                page.XmlNamespace += " lang=\"" + lang + "\"";
                page.XmlNamespace += " xml:lang=\"" + lang + "\"";
            }
        }
    }
    </script>
    

    Mike