Page 1 of 1

[Solved]Adding different stylesheet for certain pages

Posted: Sat Mar 05, 2011 2:30 am
by jasnick
Using latest version CMSMS

I need to use a different stylesheet for certain pages. Is there any way to associate a stylesheet apart from the simple adding of, and associating with, a template?

Thanks

Re: Adding different stylesheet for certain pages

Posted: Sat Mar 05, 2011 2:55 am
by Wishbone
Usage for {cms_stylesheet} is in the help. Extensions -> Tags -> cms_stylesheet

Code: Select all

{if $page_alias == 'home'}
{cms_stylesheet name='home_stylesheet'}
{/if}
If you really want to be fancy, you can define a one-line content block where the page editor can enter the stylesheet name, or leave it blank, and the value can be used to select a stylesheet, or add another one.

If you really, really want to be fancy, you can use AdvancedContent and define a multi-select with the stylesheets for the editor to select from.

Re: Adding different stylesheet for certain pages

Posted: Sat Mar 05, 2011 3:10 am
by jasnick
Thanks Wishbone - didn't think of looking there - SO much to learn!

Not looking to get too fancy!!

if $page_alias == 'home'}

Are the two == correct or is that a typo? Not meaning to be rude :)

So I set up a new stylesheet in the usual way, associate it with the template, and put the following in the head:

{if $page_alias == 'home'}
{cms_stylesheet name='secondstylesheet'}
{/if}

and repeat if more than one page will use this stylesheet. Is that correct? I leave the current stylesheet {stylesheet} in the head as is?

Re: Adding different stylesheet for certain pages

Posted: Sat Mar 05, 2011 3:46 am
by Wishbone
yes.. == is correct.

If you're using {stylesheet} for your main template css, then use {stylesheet name="secondstylesheet"} instead of {cms_stylesheet} to be consistent.

{cms_stylesheet} has a caching mechanism, and exists in /tmp, so you have to adjust your image URLs. {stylesheet} is in your document root ( / )

Re: Adding different stylesheet for certain pages

Posted: Sat Mar 05, 2011 4:03 am
by jasnick
Thanks - haven't quite got it working yet but can now see why. Will follow your instructions and mark this solved if I can get it working.
Yes, lost my background image, saw the error in the path and was wondering what to do next!

Thanks again!

Re: Adding different stylesheet for certain pages

Posted: Sat Mar 05, 2011 4:26 am
by jasnick
Thanks Wishbone - I've now got it all working!

Re: [Solved]Adding different stylesheet for certain pages

Posted: Sat Mar 05, 2011 11:15 pm
by Dr.CSS
You can also add style sheets to the metadata box in options tab when editing/making pages...

Re: [Solved]Adding different stylesheet for certain pages

Posted: Sat Mar 05, 2011 11:29 pm
by jasnick
That's interesting - thanks Dr.CSS