Last active
October 20, 2021 15:03
-
-
Save jeremy-farrance/e02362cf3e555e5278d45e6cb5dff660 to your computer and use it in GitHub Desktop.
In Dnn, Modify the HTML of the Page Output - Attributes on Body and Html Tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Control Language="C#" AutoEventWireup="True" Explicit="True" Inherits="DotNetNuke.UI.Skins.Skin" %> | |
<%@ Register TagPrefix="dnn" ... | |
... | |
<script runat="server"> | |
// Read more: https://dnncommunity.org/blogs/Post/6127 | |
// Important: for this to work, AutoEventWireup (above) needs to be True | |
protected void Page_Init(object sender, EventArgs e) { | |
// get a pointer to the Page | |
DotNetNuke.Framework.CDefault thisPage = (DotNetNuke.Framework.CDefault)this.Page; | |
// see /Default.aspx; note that this could break someday, see HtmlAttributes in Default.aspx.cs | |
// get a pointer to the Literal inside the <html> tag | |
litHtml.Text = "class=\"no-js\" " + litHtml.Text.Trim(); | |
// get a pointer to the <body> tag (control) | |
var tagBody = (System.Web.UI.HtmlControls.HtmlGenericControl)thisPage.FindControl("Body"); | |
AppendCssClass(tagBody, "site"); | |
tagBody.Attributes["data-component"] = "Site"; | |
} | |
public static void AppendCssClass(HtmlGenericControl control, string cssClass) { | |
// Ensure CSS class is definied | |
if (string.IsNullOrEmpty(cssClass)) return; | |
// Append CSS class | |
if (string.IsNullOrEmpty(control.Attributes["class"])) { | |
// Set our CSS Class as only one | |
control.Attributes["class"] = cssClass; | |
} else { | |
// Append new CSS class with space as seprator | |
control.Attributes["class"] += (" " + cssClass); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read more in a Blog article here: DNN Details 002: Fine Tuning Your HTML Output in DNN