Site structure
Version 5.x > Site structure > Move <script> to immediately after <head> View modes: 
User avatar
Member
Member
k.yanagi - 4/11/2012 9:03:33 PM
   
Move <script> to immediately after <head>
Hi. :)

Is there a way to move a script that's placed using the Head section of the Page Templates area in CMSDesk? I am using one master file and around 3 physical aspx files to create several different templates in Kentico and only one of those templates needs to have a script placed immediately after the <head> tag.

If this can be done in a way that it will only affect that 1 template, that would be really great. However, just being able to move the contents of the Head section of the Page Templates area in CMSDesk to immediately after the <head> tag, even if it affects all the pages would be fine as well. I just need to be able to move it, if it's possible.

Thank you in advance for your replies!

User avatar
Member
Member
k.yanagi - 4/11/2012 9:05:14 PM
   
RE:Move <script> to immediately after <head>
Sorry, I forgot to mention that I am asking because I am looking for a way to do this without having to create a different master and physical aspx file for just 1 page.

Thanks again!

User avatar
Kentico Support
Kentico Support
kentico_janh - 4/12/2012 7:02:04 AM
   
RE:Move <script> to immediately after <head>
Hello,

Sure, this can be done very easily. We have a Head HTML code web part for it, so you can just place it on that page/template you have mentioned and fill its HTML code property with your own code. The only problem is, that this web part appends your code before the ending head tag and you want to have it immediately after the head tag, so please just edit the web part's source code in the \CMSWebParts\General\headhtml.ascx.cs file and update the OnPreRender method:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

if (this.StopProcessing)
{
// Do nothing
}
else
{
// this.Page.Header.Controls.Add(new LiteralControl(this.HTMLCode));
this.Page.Header.Controls.AddAt(0, new LiteralControl(this.HTMLCode));

}
}

Best regards,
Jan Hermann