Please can I have your feedback about the themes changes in Moodle 2.0

Please can I have your feedback about the themes changes in Moodle 2.0

by Tim Hunt -
Number of replies: 14
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
More progress on the themes changes in Moodle 2.0. I have just checked in another huge chunk of work which moves the code that outputs the blocks out of different scripts all over Moodle and into the theme layout.php files. (It was about 1200 lines of code edited and 900 deleted).

I have also just updated Development:Migrating your code to the 2.0 rendering API#Themes which explains what you have to do to update a Moodle 1.9 theme to be a proper Moodle 2.0 theme. (However Moodle 1.9 themes still 'work' unmodified with Moodle 2.0. I wasn't expecting that to be possible.)


So, now is a good time to look at what I have done. On the one hand this is close enough to 'finished' that you can now see how things are going to work. On the other hand, it is not too late to change things further if don't like it, or can think of ways to make it better.

One of the goals of these changes was to make it eaier to theme Moodle. I have been mentoring Olli as a GSOC student this summer to work on Moodle usability. Olli keeps saying that you have to test your interfaces with real users. Well applying that is a slighly distorted way, my interface is the themes API, and you (and core/plugin developers) are the users, so I can only make things better with your input.

I am also looking forwards to seeing converted versions of some of the better core themes (anomaly, custom_corners, ...) in due course, that take advantage of the new options. So far, I have only fully converted standard and standardwhite themes, and the aim there is just to be backwards compatible, so that is not very exciting.


Some warnings:
  • adding/editing/deleting blocks is currently broken. Making that work again is next on my to do list.
  • Making these changes was a big enough problem, so to my eternal shame and as a temporary measure I resorted to a layout table in theme/standard/layout.php. It would be a big help if anyone can change that to a table-less layout for me. (MDL-19757)*
Looking forwards to hearing your comments. (I hope wink)


* I know that in MDL-19077 several people gave me suggestions for table-less layouts. Except that what I actually got was a link to a page that lists 30 different layouts, which is something of a mixed blessing ...
Average of ratings: -
In reply to Tim Hunt

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Dan Humpherson -
Tim,

Just downloaded the latest Moodle 2.0 release and installed on server but i've come up against a problem.

Im using the layout.php from your example here:

http://docs.moodle.org/en/Development:Migrating_your_code_to_the_2.0_rendering_API#Themes

This is my config.php file:


// Code in theme config.php
$THEME->layouts = array(
// Most pages. Put this first, so if we encounter an unknown page type, this is used.
'normal' => array(
'layout' => 'standard:layout.php',
'regions' => array('side-pre', 'side-post'),
'defaultregion' => 'side-post'
),
'home' => array(
'layout' => 'layout-home.php',
'regions' => array('side-pre', 'side-post'),
'defaultregion' => 'side-post'
)
);

However its not picking up the layout.php or layout-home.php files?

Are pointers?
In reply to Dan Humpherson

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Dan Humpherson -
Think my CVS may be screwed and as such havent got the latest version.... Sorry!
In reply to Tim Hunt

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Frank Ralf -
Hi Tim,

I checked out the latest version from HEAD but didn't get very far (see screenshot). sad

Attachment _2009-07-09_HEAD_error.png
In reply to Frank Ralf

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Frank Ralf -
Finally managed to login an run the update script. Admin pages look OK but opening the main page still results in the above error message.

And additionally I got the following error message when running cron:

Warning: Attempt to assign property of non-object in J:\XAMPP\htdocs\moodle_HEAD\moodle\mod\feedback\lib.php on line 44

hth
Frank
In reply to Frank Ralf

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Dan Humpherson -
How I have got HEAD from CVS (Bah proxy issues - shakes fist) all seems fine, looking at creating a 3 column layout in pure css.
In reply to Frank Ralf

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
OK, I should have recognised that as the formal_white theme. I just tried an new install with $CFG->theme = 'formal_white'; added to config.php and it worked for me.

In reply to Tim Hunt

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Mauno Korpelainen -
Basicly everything I have so far tested has worked as documented - but I have not yet tried to modify all possible small details.

$THEME->layouttemplates = array(
'normal' => 'layout.php',
'home' => 'layout-home.php',
);

in custom theme config.php gave a perfect start to use modified layout files ... but these new $THEME settings have changed a couple of times during the last weeks so it would not be a surprise if some current settings are not documented...

Like Patrick many of us have vacations - I will be back after 5 days and could modify some themes then...


In reply to Mauno Korpelainen

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes, stuff has changed a lot recently. The point of my post was to say that I think it has stabilised now (I hope).

However, perhaps I should have waited a day for CVS mirrors, download packages, and http://phpdocs.moodle.org/HEAD/moodlecore/theme_config.html to be updated. Sorry, I was impatient.

Mauno, your config.php is now outdated because of the last lots of changes. Sorry.

Frank, are you still having problems? Which theme are you using there? New install with any 1.9 theme should not give errors like that. Let me know which theme and I will test.
In reply to Tim Hunt

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Patrick Malley -
Hello Tim,

I apologize for not providing feedback sooner. I am a the end of three grad classes I regretfully took on this summer, so I came back from my vacation with quite a bit of work to do. Luckily, they finish this week so I'll be able to devote more time to this.

Overall, this accomplishes all of my goals outlined here back in February. The use of layout.php with the ability to put blocks where you'd like works well for my purpose.

I wonder, though, if the flexibility you offer could be extended to other pages down the road. Can we designate layout-quiz.php now or our options limited to the one's you've listed? If they are limited, could this list be theoretically expanded in the future?

I will focus my energy on MDL-19757 over the next few weeks. If I have questions as I go I'll let you know.

Thanks a million for the incredible work you've done on this. It really is a remarkable change.
In reply to Patrick Malley

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
No real rush other than that I am impatient wink

And http://patrickmalley.com/2009/02/18/the-case-for-moodle-templates/ was a very helpful blog post. It made the requirements very clear, and yes, it should be possible to do everything you asked for there, becuase that is one of the things I had in mind when designing the new system.


Help with MDL-19757 would be greatly appreciated, although there is no real rush, it just needs to be done before the Moodle 2.0 release. However, it would be reassuring to know that it is possible. By the way, it would be nice if it could be done without the JavaScript that anomaly requires.


layout-quiz.php is really a separate thing. Actually, what are you asking for? As you asking for
  1. different regions to put blocks on quiz pages, or
  2. a way to control what happens in [MAIN CONTENT GOES HERE] on quiz pages?
In reply to Tim Hunt

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Patrick Malley -
Actually, what are you asking for?


I was asking for control over what happens in {MAIN CONTENT GOES HERE| without really thinking about what I was asking! The current system does provide theme developers the freedom to:

1.) Alter the layout of the page (sideblock regions can go anywhere in layout.php).

2.) Add custom divs and classes around the main content (which was once the middle column) and the sideblocks and their regions.

3.) Create separate templates for different types of pages (forms, popups, etc.).

But you have not implemented a complete templating system to control the main content at all. Is this something you still plan to do, or are you going to stop here?

I ask because the benefit of a templating system that allowed theme developers to pull out pages (say the quiz-view page) would give guys like Urs and me the opportunity to mess with the existing layouts on a per-client basis. For example, if I have a client who wants to change something in the main content of the quiz-view page, I can do it without hacking the core code.

I know multiple arguments for such a system have already been made, but let me just clear my mind of these three:

1.) Theme developers should ideally be able to meet the needs of their clients. There are several times when I have to tell my clients that something is not possible because I don't have access to it in the theme folder. It is a limitation of the software to have have to tell someone that something is not possible without sacrificing .....

2.) Urs is a really creative guy and has an eye for what works with design. I'd love for him to have a realistic opportunity to change the templates for his clients and reintroduce the strong elements that he realizes back into the Moodle core.

3.) One of the reasons there are so many developers for Wordpress is because of its flexibility and dedication to design. I know that Moodle is more complex than Wordpress as a system, but I can't help but think that more flexibility would bring in more competent designers.

Perhaps I shouldn't have listed these since I know the argument has already occurred, but they were on the tip of my tongue so why not. It might also be the case that you're still planning to implement this system, and I've just missed something. So, I guess some clarification on this would be nice.
In reply to Patrick Malley

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
First, can we agree that it will never be possible, nor is it desirable, to be able to to change any part of Moodle from a Theme. Depending on what you want to influence, it may be a theme/design change, it may be a change that admins should be able to control with a config option, or it may be something that requires a custom plugin/code hack. And the boundaries between those three things are very blurred.


Anyway, you have missed something, and that is the 'renderers' part of the changes.

As a very crude example have a look at http://cvs.moodle.org/moodle/theme/custom_corners/renderers.php?view=markup. That is not a great example, because it is very PHP-ish code, rather than template-ish code - but that can, and probably should, be changed as some point. Also, what it achieves is rather limited.

Anyway, the point is that in Moodle 1.x, the custom corners theme was only possible with core code hacks in weblib.php, with if ($THEME->customcorners) { // Do one thing } else { // do something else } in functions like print_box and print_side_block. Now, that sort of customising of HTML can be done entirely within the theme.

Now, moodle_core_renderer (defined in lib/outputlib.php, and not finished yet. Nicolas Connault is working on it, see MDL-19756) replaces all the old functions in weblib.php and makes them available for themes to change the HTML that is output for basic bits of HTML like a box, or a block on the side of the page, or ... but that is not really what you are asking for. ...

(Although, if you are really desperate, in your themes overridden renderer, in the ->box method, you could start writing code like if ($page->pagetype = 'quiz-view' and $id = 'intro') { to generate different HTML. Yuck!)


Anyway, the bit you are really asking for in phase 2, which is mostly not going to happen until after Moodle 2.0 (because it is a huge job, and we would like to see Moodle 2.0 released this decade if possible wink).

In phase 2, to go along-side moodle_core_renderer, we start to define things like moodle_mod_quiz_renderer. moodle_mod_quiz_renderer will have much higher-level functions like, for example

function view_page($quiz, $previousattempts, $startorcontinueattemptbutton, ...) {

}

And the default implementation of that function is most of the code that is currently in http://cvs.moodle.org/moodle/mod/quiz/view.php?view=markup, after the comment "/// Print the page header".

Actually, that is not the best example page, because it is very hard to separate presentation from logic there. What a student can and can't see about their quiz attempts is not just a presentational decision, but business logic that people care passionately about.

A better example would be http://cvs.moodle.org/moodle/mod/quiz/attempt.php?view=markup. Again the idea is that almost everything after "/// Print the quiz page ////////////////" goes into moodle_mod_quiz_renderer::attempt_page(...)

Then the point is that mytheme, can choose something different to be output by defining, in theme/mytheme/renderers.php, a mytheme_mod_quiz_renderer, and hopefully the code in there can look quite template-y.

It will still be the case, I expect, that the stuff output by the attempt_page(...) method ends up being embedded into the [MAIN CONTENT GOES HERE] part of layout.php. (Hmm. Actually, that is not a given.) To me that seems like an entirely sensible way to ensure consistency and avoid duplicating the layout.php code in hundreds of different templates. (A Moodle site needs about 650 different full-page templates, that is estimated by the number of places the print_header function is called.)


Of course moodle_mod_quiz_renderer::attempt_page(...) is also not a typical example, because most of what you see there are the questions, and as questions are their own sort of plugin, what a multiple-choice question looks like will probably be controlled by moodle_qtype_multichoice_renderer::question(...) - but the advantage of that is that wherever a multiple choice question appears (e.g. in a lesson) it will look the same.


So, anyway, that is where we are trying to go, but as I say, it will take some time. Longer even than Moodle 2.0 wink
In reply to Tim Hunt

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Patrick Malley -
What you've done is a vast improvement that will both help me do my work and bring us some very different themes that I'm excited to get to work on. I'm satisfied for the short term. smile

Thanks again, Tim.
In reply to Tim Hunt

Re: Please can I have your feedback about the themes changes in Moodle 2.0

by Mauno Korpelainen -

Thank you Tim for these examples.

I have so far played with home page layout and blocks and one big advantage of replacing header.html - content -footer.html combination with files like layout-home.php is that you can actually use any web templates and just put moodle as a one piece or many pieces to this previous theme format.

I'm a member of Rocket theme club so I downloaded the latest club theme and made a modified moodle 2.0 version for a start and placed first content area of moodle inside the code of different modules in different positions of this theme (not to wrapper) - all javascripts (jquery & mootools) worked with moodle 2.0 but not in moodle 1.9. Next I tested using same style for blocks with renderers.php and modified function block() and that worked well too.

The main idea of renderers and layout files is just perfect... New 2.0 themes need still a lot of testing in different browsers etc but

"That's one small step for Tim, a giant leap for themes of moodle" wink