Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

CMS5 Custom CSS property in Header?

Vote:
 

Hi. I have a question. How would I go about adding custom css to the header? For example, I would like to create an XHTML property for Standard Page (page type) and then have the custom css display in the header after the meta tags and stylesheet link tags.

I would turn off all the Properties for Editor, such as Bold, Italics, Underline, Font, Numbered list, etc. I want only the text to display. I know people have used the XHTML property like this before to display custom javascript without having the code rewritten. I think this would work for the css. Or am I wrong?

Is there a way to do this?

#49417
Mar 16, 2011 13:28
Vote:
 

Oooops.... nevermind.

I had my code to display the property in the wrong file. It works now.

But for anyone wondering, this is how I did it.

1) Add a property to your page type. In my case, I named it "CustomCSS".

2) Set property as XHTML string, and under Properties for the Editor, uncheck all boxes so that only code will display.

3) In Header.ascx, add <%= CustomCSS %> where you want it to display.

4) In Header.ascx.cs, I added code to display the string:

protected string CustomCSS
  {
    get
       {
          if (CurrentPage.Property["CustomCSS"] != null)
          {
            return CurrentPage.Property["CustomCSS"].ToWebString();
          }
          return string.Empty;
        }
   }
    

Now you can go into your page and add your custom css into your property. I left it as xhtml string to give the option of either adding some simple css, then I can use <script type="text/css"></script>. But for more complex css, I can add css <link> tags to a custom stylesheet. It would also be easier to find the property if you added a custom tab, and placed the property in that tab.

#49419
Mar 16, 2011 14:25
Vote:
 

Hi!

If your just interested in creating a string that should not be editable by an html editor you can just use PropertyLongString instead of PropertyXhtmlString.

Regards
Linus Ekström
EPiServer Development Team

#49425
Mar 16, 2011 17:08
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.