Change stylesheet based on page

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
tam10

Change stylesheet based on page

Post by tam10 »

Using the sticky post about changing content based on current page as a guide, I put this together:

Code: Select all

{if empty($csstheme)}
    {stylesheet name="(default stylesheet name)"}
{else}
    {stylesheet name=$csstheme}
{/if}
Using this you can change the attached stylesheet per page, without changing template. To use it, put the code above in the template file, below the {metadata} tag. Then in the pages where you want a non-default stylesheet, put the following in the metadata field:

Code: Select all

{assign var='csstheme' value='(stylesheet name)'}
You can use {stylesheet} as well to include stylesheets that are included in all pages. Just remember to remove the one referenced above from the template.

This code accesses the stylesheets stored in the database, rather than external .CSS files.
savagekabbage
Forum Members
Forum Members
Posts: 75
Joined: Mon Apr 23, 2007 3:51 pm
Location: Northern Virginia, United States

Re: Change stylesheet based on page

Post by savagekabbage »

Couldn't you also just put a :{stylesheet name='DefaultTheme'} in the page metadata?

Edit: Never mind, I see now that your point is to completely change the associated stylesheets :)
Post Reply

Return to “Tips and Tricks”