Adding block to course categories in Moodle 2.0

Adding block to course categories in Moodle 2.0

by Mary Cooch -
Number of replies: 8
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Just trying to get my head around the new way blocks work - if I want to display a block only on the course/index page and each course category page (and nowhere else) then do I add the block on the course/index page and set it to appear in subcontexts:yes and pagetype: admin* ?? Thanks
Average of ratings: -
In reply to Mary Cooch

Re: Adding block to course categories in Moodle 2.0

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
No -that's wrong! that doesn't disply for your average user of course; only the admin. Back to the drawing board..I'm stuck - * displays everywhere, admin* only displays for admin sad What am I missing?
In reply to Mary Cooch

Re: Adding block to course categories 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
This is where the new UI could do with being improved.

To understand the new blocks system, you really need to draw a two-dimensional diagram (or, to put it more simply, a table!).

In one dimension, you have the contexts, and you can choose that the block appears either in just one context, or a context and all its sub-contexts.

In the other dimension, you have page type, which is something like course-index or course-category or mod-quiz-view. You can choose for a block to appear on a specific page type, or any page type matching a particular pattern like course-*

A particular Moodle page is defined by the context it belongs to, and the page type.

So, you want a block to appear on page type course-index - and there is only one of those, belonging to the system context; and on all the course-category pages, and there is one of those belonging to each category context.

I think the only way to achieve that is to use two different block instances.

* One that appears on system context/course-index.
* A second that appears in system context and all subcontexts/course-category.


If you have any thoughts on what sort of user-interface would have helped you to work that out on your own, please tell us!
In reply to Tim Hunt

Re: Adding block to course categories in Moodle 2.0

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
I get it now thanks ! And when I have worked out how I'd explain it to somebody else I'll let you knowsmile
In reply to Mary Cooch

Re: Adding block to course categories in Moodle 2.0

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Actually -no - I don't get it - in order for it to appear on all the different course category pages I'd have to put it in manually in each category, so it seems to me?I can't see where to get system context and all subcontexts course-category?
In reply to Mary Cooch

Re: Adding block to course categories in Moodle 2.0

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
..and finally (this is doing my head in..) I want just one instance of a block on the page /course.index.php but I want it visible by all not just admin. So I set the block to appear in subcontexts: no and with the *. (any other page type would have made it only visible to admin) Works fine for guests etc but for admin when I go to anywhere in site admin such as the block is also available there - is correct? How can it be made only to appear on one page for everyone, admin included or is that not possible?
In reply to Mary Cooch

Re: Adding block to course categories 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
It should appear for everyone if you set page type to site-index, shouldn' it?
In reply to Tim Hunt

Re: Adding block to course categories in Moodle 2.0

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
If I set up a block on the page course/index.php the page types options I have are admin-course-index. admin-course-index*,admin-course, admin-course* , admin-* or just *. If I set it to * and with subcontext = no, then that's fine as all users can see it just on that page. Problem is, admins can also see the block on their site admin pages and I wondered if this was normal? If so, fine; if not, I am confused.
In reply to Mary Cooch

Re: Adding block to course categories 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
Ah right. I think I understand what the issue is now, but not the solution.

course/index.php has a sort-of double life.

When editing is off, it is a way for normal users (and admins) to browse a list of all courses.

When editing in on, it is a way for admins to manage the list of categories.

In the former case, the page type is course-index. In the latter case, some hackery to do with admin pages changes the page type to admin-course-index.

Actually, I think there is a clear best solution: Make a separate course/managecategories.php page for admins, and keep course/index.php just for browsing in all circumstances. However, this is a certain amount of work. I hope Sam Hemelryk, or someone like that has time to work on it.