Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Theme directory guide

From MoodleDocs
Revision as of 10:24, 18 June 2007 by Helen Foster (talk | contribs) (cat edit)


In the standard Moodle distribution, all themes are placed in the theme/ directory, this leads to developers hardcoding this location into their themes and references to themes. Developers should not take this location for granted, instead using the variables which moodle provides for the purpose of specifying a theme location.

Starting with 1.7, moodle will fully support changing the location in which themes are stored. Developers need to ensure they are using the provided variables to ensure compatibility with this feature.

$CFG->themewww

This variable has been available since version 1.5.1

The $CFG->themewww variable contains the web-accessible location of the theme directory. If it is not set by the site administrator it will be the default of $CFG->wwwroot . '/theme'. i.e. 'http://my.moodle.site/theme'.

$CFG->httpsthemewww

Moodle1.7

This variable will be introduced in version 1.7

The $CFG->httpsthemewww variable contains the same information as $CFG->themewww with the correct http/https prefix. This should be used to provide proper references to files on pages which could be https protected.

$CFG->themedir

This variable has been available since 1.5.1

The $CFG->themedir variable contains the local location on the moodle server of the theme directory. If it is not set by the site administrator it will be the default of $CFG->dirroot . '/theme'. i.e. '/my/moodle/location/theme'.

How to refer to the directory of the current theme

The most common use of the theme directories will be used to specify the current theme directory for inclusion/display of files.

The correct way to specify the http path to the directory is:

$CFG->themewww .'/'. current_theme()  

The exception to this is when specifying http theme paths which might be displayed on secure pages. In order to specify the http path to the theme directory (allow for a secure url), developers should use:

$CFG->httpsthemewww .'/'. current_theme()  

In order to refer to the local path to theme files, developers should use:

$CFG->themedir .'/'. current_theme()