[Solved]Adding different stylesheet for certain pages

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
jasnick
Power Poster
Power Poster
Posts: 695
Joined: Sat Jan 15, 2011 8:36 am

[Solved]Adding different stylesheet for certain pages

Post 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
Last edited by jasnick on Sat Mar 05, 2011 6:27 am, edited 1 time in total.
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Adding different stylesheet for certain pages

Post 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.
jasnick
Power Poster
Power Poster
Posts: 695
Joined: Sat Jan 15, 2011 8:36 am

Re: Adding different stylesheet for certain pages

Post 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?
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Adding different stylesheet for certain pages

Post 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 ( / )
jasnick
Power Poster
Power Poster
Posts: 695
Joined: Sat Jan 15, 2011 8:36 am

Re: Adding different stylesheet for certain pages

Post 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!
jasnick
Power Poster
Power Poster
Posts: 695
Joined: Sat Jan 15, 2011 8:36 am

Re: Adding different stylesheet for certain pages

Post by jasnick »

Thanks Wishbone - I've now got it all working!
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: [Solved]Adding different stylesheet for certain pages

Post by Dr.CSS »

You can also add style sheets to the metadata box in options tab when editing/making pages...
jasnick
Power Poster
Power Poster
Posts: 695
Joined: Sat Jan 15, 2011 8:36 am

Re: [Solved]Adding different stylesheet for certain pages

Post by jasnick »

That's interesting - thanks Dr.CSS
Post Reply

Return to “CMSMS Core”