Note: You are currently viewing documentation for Moodle 3.6. Up-to-date documentation for the latest stable version of Moodle is likely available here: Theme directory guide.

Development:Theme directory guide: Difference between revisions

From MoodleDocs
No edit summary
Line 21: Line 21:
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'.
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 current theme directory ==
== 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.
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 do this is:
The correct way to do this is:

Revision as of 14:32, 8 October 2006


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 which themes are stored in. 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

Template:Moodle 1.7 This variable will be introduced in version 1.7

The $CFG->httpsthemewww (introduced in Moodle 1.7) variable contains the same information as $CFG->themewww with the correct http/https prefix. This should be used to provide proper operation of https protected pages.

$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 do this is:

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

Or to include a theme file:

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