Jawad Khan

Jawad's Lodge - The willingness to torture yourself before others is what makes a developer truly a unique breed.
posts - 45, comments - 117, trackbacks - 162

My Links

News

Archives

Post Categories

Image Galleries

How to use different CSS Files in the Same template for Different WebSites in MCMS 2002 ...

Microsoft Content Management Server 2002 makes it easy to create multiple websites using the same template set. This feature is very useful if you are creating sites that require different feel and look but same/similar functionality or at-least share some templates between each other.The challenge here is how to add a CSS to the rendered posting so the feel and look is different depending on which MCMS Site Hierarchy you are in.

   Following is the solution. This solution allows you to treat CSS files as normal Content and hence can be managed by MCMS and also incorporates the MCMS work flow. Doing so allows the Desktop individuals to make changes to the CSS without bothering the IT team.

This implementation make use of the XML PlaceholderControl that I posted earlier in this Blog

In the .aspx file 

In the Register Control Section :

<%@ Register TagPrefix="cnsCtl" Namespace="Jawad.Cms.CustomPlaceholders" Assembly="Jawad.Cms" %><%@ Register TagPrefix="cc2" Namespace="Cdi.Ces.Cms.CustomPlaceholders" Assembly="Cdi.Ces.Cms" %>

(inside the HTML Body)  :

  <form id="Form1" method="post" runat="server">
   <cnsCtl:XMLPlaceholder id="PLContentPlaceholder" runat="server" PlaceholderToBind="plSinglePlaceholder" TextBoxHeight="800"
    TextBoxColumns="100"></cnsCtl:XMLPlaceholder>
  </form>

   Now in the Code behind file :

  protected Jawad.Cms.CustomPlaceholders.XMLPlaceholder PLContentPlaceholder;
  private CmsHttpContext ctx;

  private void Page_Load(object sender, System.EventArgs e)
  {
   if ( !IsPostBack)
   {
    ctx =  CmsHttpContext.Current;
    if ( ctx != null)
    {
     if ( ctx.Mode == PublishingMode.Published)
     {
      Posting pst = ctx.Posting ;
      if ( pst != null )
      {
       Response.Write (((XmlPlaceholder)pst.Placeholders ["plSinglePlaceholder"]).XmlAsString);
       Response.End ();
      }
     }
    }
   }
  }

Once finished the .aspx file you need to create the MCMS Template lets say named “CSSTemplate” using MCMS Explorer from Visual Studio.Net and add an XMLPlaceholder definition to it named plSinglePlaceholder

Now you can place that posting in the Site Hierarchy you want For example

/Channels/PetShop/en-Ca/ConfigFiles/SiteCSS

another site on same server

/Channels/ToolShop/en-CA/ConfigFiles/SiteCSS

Where SiteCSS is posting name and other elements are channels in the Path.

When you create a new template you can add the CSS files as follows in to your template ....

<link href="<%= GetCSSPath() %>" type=text/css rel=stylesheet>

The GetCSSPath is a function that gives the Path to the CSS Posting ....Its implementation is as follows ( Please correct syntax errors if any)

public string GetCSSPath()
{
    string path = string.Empty;
    CmsHttpContext ctx = CmsHttpContext.Current;
    if ( ctx != null)
    { 
      string currentPostingPath = ctx.Posting.Path;
      string siteName = currentPostingPath.Split('/')[1]; // Second Element is always site Name
      // You might want to use dynamic approach to find complete path I am hard coding the fix elements here.
     path = string.Format("/Channels/{0}/en-CA/ConfigFiles/SiteCSS",siteName);
    }
    return path;
}

Print | posted on Monday, June 20, 2005 2:09 PM | Filed Under [ Microsoft Content Management Server ]

Feedback

Gravatar

# re: How to use different CSS Files in the Same template for Different WebSites in MCMS 2002 ...

What if I use plain XHTML?
2/15/2006 8:46 AM | Mike O'Neil
Gravatar

# re: How to use different CSS Files in the Same template for Different WebSites in MCMS 2002 ...

Sure Mike I have not tried with XHTML. The Placeholder used to store CSS is XML content Placeholder.

You migh also want to look at MCMSfaq.com site for the

XHTML compliant MCMS placeholder by Steve Walker

posted there.
2/15/2006 7:29 PM | Jawad Khan

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 7 and 2 and type the answer here:

Powered by: