Merge styles_layout, styles_color, etc... in one file?

Merge styles_layout, styles_color, etc... in one file?

by Jan Dierckx -
Number of replies: 4

Trying to learn CSS, I read about the reasons behind splitting the theme file into styles_layout, styles_color, etc...

Somehow I get confused having to make changes in three different files, when I want to change the look of a specific item. It would seem easier to locate the specific element inside the css file and then have fonts / color and layout specified in the same spot.

I noticed that Joseph's Orangechoc theme has all the css in exactly one file. But of course this theme is already a very developed theme (having 2 column layout, etc...) It may be easier to start from the standard theme.

What would be the best way to proceed?

  • Use Joseph's theme

  • Merge the files of the standard theme into one CSS file. I am familiar with vim, so I could use some regular expressions to do this. Are there any tools that could be used to do this thing?

  • Continue using the separate files. It really is the best way to go. It may look harder in the beginning but has serious advantages afterwards.

Average of ratings: -
In reply to Jan Dierckx

Re: Merge styles_layout, styles_color, etc... in one file?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Jan,

Since you mention my orangechoc theme, I feel obliged to answer your postwink.

You are welcome to use, edit, hack, destroy my orangechoc theme. However, because it is very elaborate and contains some elements of customization which may be hard to understand, I would not recommend it as a starting point for making your own theme.

As regards the pros and cons of having a theme split into 3 or 4 different files.
  • The "official' point of view (if there is such a thing in our community) is that separating colors, layout and fonts in a given theme makes for easier customization for themes which are derived from that theme. For instance, you may want to only change the color scheme of a certain theme; then you would only customize the styles_color.css stylesheet.
  • On the other hand, I agree with your view that "It would seem easier to locate the specific element inside the css file and then have fonts / color and layout specified in the same spot." That is why I have only one file in my own theme. It took me quite some time to merge the standard theme's 3 files (I am not using styles_moz.css) into one!
The styles.php files

You should know that there are a number of styles.php files residing within various Moodle folders, to provide minimum formatting for specific blocks & modules. While I agree that this is useful, it complicates the task of theme creators, as you have to look into all of those styles.php files and copy all or part of their CSS classes into your own theme's files if you want to over-ride them. Plus I regret that those stylesheets have a PHP extension when they should have a CSS extension. This makes it difficult to edit them in a CSS editor.

Documentation

Take heart! Creating a new theme takes a lot of time and effort, but I have found it very rewarding.

Joseph

In reply to Jan Dierckx

Re: Merge styles_layout, styles_color, etc... in one file?

by Urs Hunkler -
Picture of Core developers

Hi Jan,

great to hear that you start working with CSS.

I strongly vote for:

"Continue using the separate files. It really is the best way to go. It may look harder in the beginning but has serious advantages afterwards."

When you read about the reasons you surely will understand that it is better to base your theme on the standard theme than to see it breaking apart when the Moodle page structure changes.

And you can go a forth way:

Chameleon writes all properties into one CSS file. When I tune Moodle Themes I use Chameleon. After tuning I separate the added properties from the Chameleon CSS into the three Moodle CSS files.

With Chameleon you will get faster results and will learn a lot about the Moodle CSS structure just by styling Moodle pages. You can use the dialogues or the "Free Edit" area. In the free edit area you may edit the CSS as you would in your editor.

Chameleon and Vim is my software of choice for Moodle theme design wink

By the way, with "css21.txt" you get a CSS help doc for Vim.

In reply to Jan Dierckx

Re: Merge styles_layout, styles_color, etc... in one file?

by Patrick Malley -
First of all, I would listen to Joseph and Urs. 

I merged all three files together (layout, font, color) for my fixed-width theme.  I went one step further (as did Joseph with Orangechoc) and eliminated using the standard theme.  I hacked Moodle quite a bit in this theme and didn't want massive cascades or load times.  For example, I didn't want to load my tab img files over the standard tab img files. 

In reality, however, I'm not sure my efforts paid off.  I still have a big, fat, complicated theme!

Basically, here's what you need to ask yourself:
  1. Will you be the person doing all editing and upgrading in the future?  I ask because, if not, you may want to stick with Urs's suggestion and not stray from the Moodle css format.  The difference between your theme and the standard theme could confuse a third party (as in the case with trying to modify Joseph's Orangechoc).
  2. How modified will your theme be?  If the answer is 'not that modified,' then I wouldn't mess with the structure for practical reasons - like time.
  3. Do you plan to share your theme with the community?  If so, you may want to keep the structure that we're all familiar with.
 So, I give you a complicated answer to your question and refuse to pick from your list.  It's simply up to you and your particular situation.  Good luck.
In reply to Patrick Malley

Re: Merge styles_layout, styles_color, etc... in one file?

by Jan Dierckx -

Patrick, Joseph, Urs,

thanks for the advice. I will use the separate files approach and try to make the best of it (using the chameleon theme)