1.5 Themes Basics

1.5 Themes Basics

by Urs Hunkler -
Number of replies: 23
Picture of Core developers

Hello,

the growing number of questions relating to the Moodle 1.5 themes made me think how I can give some overview. I will write here a serial of short sections over the next time. Each will cover one topic of the Moodle 1.5 themes.

Please ask and comment on each written topic here.

To propose topics, make general comments about the 1.5 themes, how they work etc. please use the parallel thread "1.5 Themes Question Collection".

The first sections will explain the themes structure. Hands on documentation will follow.

With the 1.5 themes we can build great Moodle learning environments - our learners will appreciate it. I'm looking forward to see those many good useable and different and attractive looking Moodle learning sites. I know learning with fun is better learning wink

Urs

Average of ratings: -
In reply to Urs Hunkler

What is Inside the Themes Folder?

by Urs Hunkler -
Picture of Core developers

In the themes folder you see the following files

pix/
config.php
favicon.ico
footer.html
header.html
styles.php
styles_color.css
styles_fonts.css
styles_layout.css
styles_moz.css

The pix folder with all pictures and icons used in the theme. The 1.5 themes come with pictures for the tabs and eventually for the gradients. (All Moodle 1.5 themes use the pix folder.)

The favicon.ico is the small icon shown in the browsers in front of the URL. (like 1.4)

header.html and footer.html contain your logo, the login, the jumpto menu, the breadcrumb navigation the moodle logo etc. Within these files you can give Moodle your individual look for the top and the bottom of all pages. (like 1.4)

styles.php has the same name as in 1.4 but takes another task. It is called from header.html and builds the bridge to the CSS files. You don't need to edit anything. (changed task for 1.5.)

config.php has also the same name as in 1.4 and another task in 1.5. In this file you configure how the CSS files work together. You can build your theme onto the standard or onto any parent theme, can include or exclude several CSS files. About the details you can read in the coming article "Cascading CSS". (changed task for 1.5.)

With Moodle 1.5 started the work to clearly separate page content from page presentation for better flexibility, accessibility and for more flexible page design. The content layer of the page is represented via XHTML, the presentation layer via CSS. To connect the belonging information in both layers HTML tags and named hooks within XHTML are used. You need quite a lot of them to style complex web applications like Moodle. To give you the chance to work relatively easy for few changes of color and fonts the CSS is separated into three files:

  • styles_layout.css
  • styles_fonts.css
  • styles_color.css

styles_moz.css is special and contains Firefox and Mozilla specific formatting, especially the round borders.

More details you can read in the coming article "Find the Styles, no Need to Search". (new in 1.5.)

Last but not least theme designers can provide information about the theme and a picture preview. The picture preview is shown as preview on the theme configuration page, the info in the README file after the theme has been selected.

  • README.html
  • screenshot.jpg

With this example Moodle page you can try how the different CSS files form the look of the page. On the top right you see four links on a green bar. With the buttons you can switch the belonging stylesheets off (font-style italic) and on (font-style normal). When you switch all stylesheets off you see the content level of Moodle.

have fun.

Average of ratings: Useful (1)
In reply to Urs Hunkler

Re: 1.5 Themes Basics

by Urs Hunkler -
Picture of Core developers

Cascading CSS

Moodle Themes use style sheets to describe the "look" of Moodle by controlling the layout, fonts and colors. These are constructed by a PHP script called "styles.php" in each theme directory, and controlled by a file called "config.php" in the same place.

Moodle has a "standard" theme which is very plain and provides a basic layout for other themes to build on. Each theme may also have a "parent" theme, which will be included before the current theme.

So, depending on your settings, you may have up the three stylesheets for a theme:

  1. "standard" theme - theme/standard/styles.php
  2. "parent" theme - theme/parentname/styles.php
  3. "main" theme - theme/yourname/styles.php

Due to the cascading character of CSS the definitions in later files can overwrite the definitions in the earlier CSS files. Moodle makes extensive use of the cascading character of CSS and gives the theme designer many opportunities. They range from easy development of themes based on the existing ones with few changes up to the design of a completely individual Moodle appearance with new CSS files.

Theme designers can define and add any CSS stylesheets and name them any way as needed for this theme.

 

 

The Standard Theme

Theme Standard

Figure 1: The theme "standard" with the CSS files "styles_layout.css", "styles_fonts.css", "styles_color.css" and "styles_moz.css".

 

 

Small Changes

If you just want to make small changes to a theme like different colors or adding a logo then your new theme will include the "standard" theme (and possibly another parent theme) then define a few extra CSS styles.

For an example, of this, see the "standardwhite" theme.

It uses the file "config.php" to set the appropriate options. The first entry $THEME->sheets = array('gradients'); defines the CSS file "gradients.css" as the file with additional CSS definitions. It also specifies $THEME->standardsheets = true; which says to include all the styles from the standard theme too.

Instead of basing the theme on "standard", you could base it on another theme by specifying $THEME->parent = 'cooltheme';

Theme Standardwhite

Figure 2: The theme "standardwhite" with all CSS files from the theme "standard" plus "gradients.css" from the selected theme.

 

 

Mixed CSS - Standard Layout and It's Own Fonts and Colors

The theme "formal_white" mixes the page layout from the theme "standard" with it's own layout, fonts and colors. This way all layout changes in the standard Moodle layout are kept. This is done by setting $THEME->sheets = array('fw_layout','fw_color','fw_fonts'); and $THEME->standardsheets = array('styles_layout'); in the config file.

Theme Formal_white

Figure 3: The theme "formal_white" with the CSS file "styles_layout.css" from the theme "standard" and the individual files "fw_layout.css", "fw_fonts.css", "fw_color.css".

 

 

A Theme Using a Parent Theme (Faked)

An advanced feature is to set any existing theme as the "parent" theme and offer variant themes to this. One possible use can be to design an own theme and offer color variants of this theme to be chosen by the users according to their color preferences. The configuration could look like $THEME->sheets = array('my_layout');, $THEME->parent = 'formal_white'; and $THEME->parentsheets = array('fw_layout','fw_color','fw_fonts');

Fake Theme Formal_white_plus

Figure 4: The faked theme "formal_white_plus" with an additional CSS file.

 

 

A Theme Without Standard Dependencies

The theme "orangewhite" uses its own CSS. The settings $THEME->sheets = array('styles_layout', 'styles_fonts', 'styles_color'); and $THEME->standardsheets = false; deactivate all other Moodle CSS and make a completely independent theme. All changes in the standard Moodle theme do not change this theme at all.

Theme Orangewhite

Figure 5: The theme "orangewhite" with it's own CSS files "styles_layout.css", "styles_fonts.css" and "styles_color.css".

 

 

Some more Basic CSS Files

In addition to this theme CSS files Moodle features a basic CSS file for every module, block and for every language. Developers can provide basic CSS properties for their modules and blocks to get the page or block layout right, if they need formatting for special functionality. The look and feel of Moodle is not changed by these layout basics.

These files are only loaded when the "standard" CSS is activated. They are loaded first before all theme CSS files.

Moodle CSS Loading Order

Figure 6: The CSS file loading order of all Moodle CSS and theme CSS files.

 

 

Last but not least

Very good information about the Moodle CSS you can get from the final stylesheets that reach your browser. Moodle integrates some helpful documentation. For example you can read the CSS with the Firefox "Web Developer" extension.

Average of ratings: Useful (1)
In reply to Urs Hunkler

Re: 1.5 Themes Basics

by mark white -

Just the information I needed.

Thanks for a clear explanation.

Mark

In reply to Urs Hunkler

Re: 1.5 Themes Basics

by John Papaioannou -
Stunning! big grin

It would be great if developer-oriented documentation like this were all in one easy-to-find place. For a Moodle newbie, finding this thread in the forums might be a little intimidating, while a "developer documentation" link would be one of the first things to try.
In reply to Urs Hunkler

Re: 1.5 Themes Basics

by Rolf Mortenson -
Thanks Urs!
Having done some serious wrestling and wrangling with themes in 1.4, I'm encouraged by the progress that seems to be built into 1.5. The way css was used in 1.4 was quite haphazard, and 1.5 seems well thought out.

Your series of articles on the topic will be a big help!

In reply to Rolf Mortenson

Re: 1.5 Themes Basics

by Andy Mansker -

I'm new to Moodle. Excellent tutorial. Something that would help me is a screen capture with callouts indicating the stylesheet.css/stylename for a particular element. You can look at the screencapture.jpg and immediately see which style sheet to pen and which style to change.

Has this been done? Is it feasible and helpful to others? I will be happy to help if anyone want to pursue this (assuming it has not been done). Might even take it on myself. It would be a valuable tool for me.

In reply to Andy Mansker

Re: 1.5 Themes Basics

by Herbert Keijers -
Firefox has a nice plugin to show that sort of things: Web Developer


Attachment firefoxweb.png
In reply to Herbert Keijers

Re: 1.5 Themes Basics

by Andy Mansker -
I installed the Web Developers Extension and it does exactly what I was looking for - but much better than my suggestion.
In reply to Herbert Keijers

Re: 1.5 Themes Basics

by Ralf de Günther -
Hey,

I am new with CSS. So how must I integrate such information from the web developer? How can I change the color (text, backround, ...) from the class left side or other examples ?

Thanks for help?

Greetings

Ralf dG
In reply to Ralf de Günther

Re: 1.5 Themes Basics

by Tony Silva -
I don't want the overhead of pictures for each student and the smiley guy picture doesn't work for our site.  Is there any way to disable the member picture feature...or do we have to define it in CSS to display NOTHING?
In reply to Tony Silva

Re: 1.5 Themes Basics

by Urs Hunkler -
Picture of Core developers

Tony,

Moodle does not offer an option to disable the member picture feature. You could

work generally via changes in the theme: a) Hide the member picture by CSS. This way the pictures are transfered to the users computer, but not displayed.

Change your Moodle installation: a) Replace the default picture with a transparent gif. Your student's uploaded picture will still be shown.

b) Remove the part to upload user pictures on the user preferences page with a patch.

I highly recommend the theme way, because you get a real task to handle your patches when you update your Moodle.

Urs

PS. Many people see in personalized presence a relevant aspect in net based learning. User pictures play an important role. What makes you think they are overhead?

In reply to Tony Silva

Re: 1.5 Themes Basics

by Urs Hunkler -
Picture of Core developers

an addition - it's allays wise to look at the Moodle "config.php" and "config-dist.php" wink

in the Moodle config file you can uncomment this option to prevent users from updating their images:

// Prevent users from updating their profile images  
//      $CFG->disableuserimages = true;  

Urs

In reply to Urs Hunkler

Re: 1.5 Themes Basics

by Barry Mansfield -
Since this thread has the word "basics" in it - I'll ask my question here.  I'm currently using Kubrick and trying to place a different header inside the course (than from outside).  In 1.4 -  I knew how to do that.  It's not as obvious now (at least to me.)  Please help!
Barry
In reply to Barry Mansfield

Re: 1.5 Themes Basics

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

Hi Barry,

Sorry I don't understand "trying to place a different header inside the course (than from outside)"wide eyes. Could you please explain?

Joseph

In reply to Joseph Rézeau

Re: 1.5 Themes Basics

by Barry Mansfield -
Let me clarify - In 1.4 there were possibilities for two different headers - one for the login/entry page and another for inside an actual course. I would like to be able to modify my header and place things specific to the course there.

I'm currently using the Kubrick theme and can't seem to find out where to do this.

Barry

In reply to Barry Mansfield

Re: 1.5 Themes Basics

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Barry,
Now I understand your question. In Moodle 1.5+ You will find in file \moodle15\moodle\theme\orangewhite\header.html two sets of lines clearly marked
  1. for the header of a site's home page (login/entry/site-index page):
    <?php if ($home) { // This is what gets printed on the home page only etc.

  2. for the header of all other pages (courses):
    <?php } else if ($heading) { // This is what gets printed on any other page with a heading etc.
Or maybe what you want it to display in the header of each course in your Moodle site information specific to that course? You can display the name of the course, using the variable $heading, of course, but what other info would you like to display? I think there is a list of variable available but can' find it right now.

Joseph
In reply to Urs Hunkler

Re: 1.5 Themes Basics

by Charles Griffin -

I'm using a custom theme that comes packaged with a favicon. I changed the favicon to my own, but it continues to display the favicon that came with the theme package. Someone suggested that I purge the cache, but did not say how to purge it. Please help, if you can.

I thank The Lord Jesus in advance for your kind help.

In reply to Charles Griffin

Re: 1.5 Themes Basics

by Thomas Hanley -

Hi Charles,

To clear your browser's cache:

Internet Explorer 8

• Click on 'Tools'
• Select 'Delete Browsing History... '
• Select ' Temporary Internet Files'
• Click on 'Delete'

Internet Explorer 7

• Click on 'Tools'
• Select 'Internet Options'
• Make sure the 'General' tab is selected
• Under 'Browsing History' click 'Delete'
• Click 'Delete Files' and 'Delete cookies'

For full list of browser instructions (including Firefox) go here:

http://www.londonmet.ac.uk/weblearn/staff/how-to-clear-the-cache.cfm

Hope this helps

~thomas

In reply to Thomas Hanley

Re: 1.5 Themes Basics

by Charles Griffin -

Dear Thomas:

I thank The Lord Jesus for your kind response to my inquiry. The 411, as well as your response, was good, and I appreciate it. I resolved the problem I was having by changing the favicon name to favicon_7 in the theme's html document. I also renamed the favicon that I wanted to favicon_7. The following statement illustrates the changed code: (I suppose the name could have been any name as long as the file and link names corresponded).

<

-Charles

link rel="shortcut icon" href="<?php echo $CFG->wwwroot.'/theme/'.current_theme() ?>/favicon_7.ico" />