I realize this is issue has been marked as "won't fix", but I'd like to ask you to reconsider this decision.
Maybe Jay' s use case of teaching theme development isn't the best example, but Tim's retort that "Themes have to go in the themes folder because that is how Moodle is designed to work" flies on the face of the information contained in the Theme directory guide.
Of course, we cannot get rid of the require_once of config.php in styles.php, but it should be done in such a fashion that it works independently of where the theme is stored. I have a good use case for this: take a Moodle hosting site that wants to keep a single copy of Moodle on the disk, to make maintainance easier.
There's a nice discussion of why and how you might want to do this over at Moodle's general development forum. The solution proposed by Martin Langhoff in that thread has a serious drawback, though: the moodle root directory ends up littered with dozens of config_foo.php files. A better solution, borrowed from Drupal, is to keep virtual host-specific configuration for site foo in a directory sites/foo. Under such a scheme, the site-specific configuration for site foo is in sites/foo/config.php, while the same information for site bar is in sites/bar/config.php
Now, in such a setup, you may not want the administrator of every virtual host to be able to use the theme of every other virtual host on that particular machine — that would be bad, you may end up with your customers impersonating one another. Also, you may want to provide your users with access to upload themes to their own theme directory, without upsetting other users' theme collection. A nice extension of the same idea expressed in the previous paragraph would be to use $CFG->themedir to have a site-specific themes directory at sites/foo/themes, sites/bar/themes, and so on. Unfortunately, this doesn't work because the require_once on themes' styles.php scripts expects config.php to be exactly two directory levels above the theme, not four as in this case.
The desired effect can be achieved my placing the site-specific theme directory directly in Moodle's root, but the result is not pretty: a profusion of theme-foo and theme-bar directories cluttering up Moodle's root, and a nuisance whenever you do an upgrade and have to copy all those folders over to the new instalation (instead of just copying the one directory sites).
So, please, I ask you to reconsider this issue as a bug worth solving, not by avoiding the inevitable require_once of config.php , but rather by putting into place some way to find config.php that doesn't rely simply on ../../config.php being the right one (and failing if no such file is there).
Hi jai,
the reason for that being included there is that the styles.php script is called from all Moodle pages, in order to include the needed css contents. And all pages that are directly invoked MUST include config.php in order to get access to all the Moodle stuff (APIs, global objects and so on).
So I really think it isn't possible to avoid that require_once().
Anyway... where is the point about not to use the "theme" directory to store themes? It's like not using the "mod" dir to store modules and so on.
Ciao