Looking for the v10 manual? Visit our new user's guide!
 
Search Descriptions Version
 
 
This article applies to: ML v7, ML8

How to add head sections to pages


Synopsis
App_Code\SkinBase.cs OnPreInit removes the literal header and footer content of the .aspx page in anticipation that template.ascx will supply templatized versions of that content.  In some cases, store admins will want to use their own header/footer information for SEO purposes, skin variation, etc.  Below are 2 methods of doing this.

Procedure
First method is to add a literal control inside your template's head section:

    Code:
    <head>
    -   
    -    
    -  
    <asp:Literal ID="MyHead" runat="server"/>   
    -   
    -   
    </head>

Add an accessor to get/set the text property of the control in App_Code\TemplateBase.cs:

    Code:
    public class TemplateBase : System.Web.UI.UserControl   
    {   
              protected Literal myhead;   
      -  
      -   
      -   
              public string MyHead  
                {  
                     get  {  return myhead.Text;  }   
                     set  {myhead.Text = value;  }   
                }

And make your template instance accessible to the derived Page changing App_Code\SkinBase.cs:

    Code:
    private TemplateBase m_Template = null;

to

    Code:
    protected TemplateBase m_Template = null;

Now, in your .aspx code-behind, set your header content to whatever you want for that specific Page:

Example miscellany.aspx.cs

    Code:
    public partial class _miscellany : SkinBase   
    {  
        protected void Page_Load(object sender, System.EventArgs e)  
        {  
               //Example using Topic for CMS ease  
               int topic = Topic.GetTopicID(CommonLogic.GetThisPageName(false),Localization.GetWebConfigLocale());  
               if( topic !=0)
               {   
                   Topic headers = new Topic(topic);
                   m_Template.MyHead = string.Format(@"<meta name=""description"" content=""{0}""/><meta name=""keywords"" content=""{1}""/> {2}", headers.SEDescription,headers.SEKeywords,headers.Contents);    
                }

The second method, in your template:

    Code:
    <%@ Register TagPrefix="ASPDNSF" TagName="Topic" Src="~/TopicControl.ascx" %>  
    -  
    -  
    -  
    <head>
    -  
    -  
    <ASPDNSF:Topic ID="Headers" runat="server" />  
    -  
    </head>

In App_Code\TemplateBase.cs:

    Code:
    public class TemplateBase : System.Web.UI.UserControl  
    {
           public System.Web.UI.UserControl Headers;

In your aspx page.  Example miscellany.aspx:

    Code:
    <%@ Register TagPrefix="aspdnsf" TagName="TopicControl" Src="~/TopicControl.ascx" %>

In your code-behind file.  Example miscellany.aspx.cs:

    Code:
    protected void Page_Load(object sender, System.EventArgs e)  
    {   
           ((TopicControl)m_Template.Headers).TopicName = CommonLogic.GetThisPageNaem(false);

Note, the head content relies totally on the Topic contents.  So the Topic Description and Keywords are ignored.  In other words, code the entire head content that you want into your topic.  Example Topic named "miscellany.aspx":

    Code:
    <meta name="description" content="this is miscellaneous stuff"/>  
    <meta name="keywords" content="misc,miscalleny,miscellaneous"/>