Different Styles for Different Pages

Topics: Writing themes
Jul 30, 2012 at 7:12 PM

Good Afternoon,

I have searched online and on the forums to try to find a solution to what I need, but I have had no luck (perhaps I am searching it wrong).

I am trying to customize my orchard to load a different .css for different pages on my site. For example:

"~/~" loads site.css

"~/page1" loads page1.css

And so-on. I am wanting to do this because the two pages reflect two completely separate products. Your help is most appreciated.

Developer
Jul 30, 2012 at 8:27 PM

Maybe you could do a simple Request.Path from within your view, and build an url off of that? Something along the lines of:

string cssUrl = string.Format( "~{0}.css", Request.Path );

Obviously you either need to somehow check that the css resource actually exists before including it, or live with the fact that the browser will receive a 404 when trying to load a non-existing resource.

Alternatively, you could write a little content part which enables content items to specify a "include content specifiic css file if it exists" setting. That part's driver would then emit a shape, whose template will register a css resource, if it exists.

Alternatively, if it's just about two css files, you may as well do some if/else branching in your view.