General developer forum

 
 
Brian
Examples of Blocks that output to Central Column
Group Particularly helpful Moodlers

Can anyone point me to examples of (the code for) blocks that output to the center?  I want to add some navigation for course students for a new course format where the student can skip direct from resource/activity to resource/activity.  Thanks if you can!

 
Average of ratings: -
Brian
Re: Examples of Blocks that output to Central Column
Group Particularly helpful Moodlers

ps - ideally for Moodle 2.4 or at least 2.x

 
Average of ratings: -
Rosario playing soccer
Re: Examples of Blocks that output to Central Column
Group Particularly helpful Moodlers

As far as I know, Blocks have their own dispaly area, in the Block area. Since you can place blocks into the dock and to the left and right side, you get your output there without having to code anything special. So I guess that simply putting the block in the central area would display its contents there. But I do not know whether you can place any Block in the central column. I know of a trick we used in Moodle 1.9 to display a sitenavigation in the central column of the FrontPage. It was Kevin Treussier's Menu. Unfortunately my test-server is down, otherwise I could have shown you his navigation.

I wrote a navigation myself, sitenavigation and mycourses, if you are interested in those two blocks. I reengineered for Moodle 2.3 in the last months. Sitenavigation can be found in the Modules&Plugins Database and mycourses is in one of these threads.

Rosario

 
Average of ratings: -
Davo
Re: Examples of Blocks that output to Central Column
Group DevelopersGroup Particularly helpful Moodlers

The 'My Moodle' page allows you to add blocks to the central column by default.

A custom course format would allow you to create a block area in the central column, if you wanted that.

As far as the block itself is concerned, there is no difference between outputting to a central column and a side column, you simply return the block contents and Moodle puts it in the right place (which does mean that blocks intended to go in the central column look very squashed if put in a side column).

 
Average of ratings: -
Picture of Alex Walker
Re: Examples of Blocks that output to Central Column
Group Particularly helpful Moodlers

Blocks display their own content in the sidebar, but there are blocks that can display their own content in the centre panel. There are two ways of doing this.

The first is to create a page in the block folder and link to it from the block. This lets you have your own custom page with your own content in the centre panel, but it will take you away from the main course page, so it doesn't sound like it's what you're looking for.

You can also create a block that uses JavaScript to add its own content to the main panel. The accessibility of this is debatable, especially for users with screen readers, but it's a possibility. In fact, the 'Report Spam' block on moodle.org does this - it uses Javascript to add a 'Report Spam' link to every forum post.

You might want to look at just developing your own custom course format - especially if you've upgraded to Moodle 2.4. Just like Moodle 2 added a lot more flexibility for building themes, 2.4 added a lot more flexibility for course formats.

Here's an example of what you can do with custom course formats. Once I add some new features, I hope to release this to the community (if my employer will let me - they own the code I write). I've added the latest posts from 'News forum' to the top of the page (by shamelessly copying code from the Latest News block), and a Facebook-style list of lecturers at the top of the page. I'm known among my team for stealing ideas from being inspired by Facebook smile

If the idea interests you, the easiest starting point is probably to take a copy of the 'topics' course format and make changes to it. There are a few intersesting course formats you can get from moodle.org, such as 'Grid' and 'OneTopic'. I haven't tried either of those myself, but I have heard people talk about them.

 
Average of ratings:Useful (3)
Brian
Re: Examples of Blocks that output to Central Column
Group Particularly helpful Moodlers

Thanks All

I guess I should have been a bit clearer wink

The goal is to create a new "Page per activity" course format, where the student goes directly from activity to activity.  Most activities / resources are displayed using 'modname/view.php', which means I have a navigation problem in getting each activity to link to the next one.

My question should I guess be how can I add a central column navigation section

"<<previous activity           next activity>>"

above activities such as Book or File or Lesson etc ?

 

 

 
Average of ratings: -
Rosario playing soccer
Re: Examples of Blocks that output to Central Column
Group Particularly helpful Moodlers

OOooh, sorry, if you want to display each section/topic per Page, you just have to ENABLE this in the course Settings. And then there is a trick to get this to work with the forward - previous buttons you mention. If I am not mistaken you must double click one section.

Let me make a test and I will come back. Rosario

Here you are:

1) enable in course settings

selectOneSectionPerPage

2) simply click on one Topic Link to have it displayed on one page

clickOnLinkOfSectionToDisplayOnOnePage

3) and now the navigation links appear

nowNavigationAppears

 
Average of ratings: -
Brian
Re: Examples of Blocks that output to Central Column
Group Particularly helpful Moodlers

Your site looks good Alex!  

I have created my own "simple2" course format, and get_url() does allow me to skip empty section headings and go straight into the activities.

The course formats affect things like whether or not you have sections and how the sections are rendered.  However, the course still has to take the student to the activity itself (book/view.php, lesson/view.php etc), where there is not yet any concept of course format or navigation or even a print_modname() function.

I guess I could just modify every activity/mod's view.php and add the navigation, but that seems to be a very short term fix.

Any urls or examples of simple php or javascript still appreciated wink

 
Average of ratings: -
Picture of Alex Walker
Re: Examples of Blocks that output to Central Column
Group Particularly helpful Moodlers

Thanks.

What you're trying to do will be a bit complex to pull off. Essentially, you need two things:

  • A way of knowing which order the resources come in. This should be relatively easy, since Moodle courses are already capable of displaying this information. There must be a function you can use, or a database query you can steal from the Moodle code.
  • A way of getting Previous / Next links onto the bottom of your course pages. I would suggest building a block that has 'Previous' and 'Next' links. You could use Javascript to add them to the bottom of the main content area, and display them like WordPress displays 'Previous Article' and 'Next Article' links.

Moodle uses the YUI Javascript library. I don't know anything about YUI: I actually use jQuery everywhere. The 'central column' is actually a div with the ID region-main. If I wanted to add content to this area with jQuery, this is what I'd do:

$("#region-main").append('<p>This is a paragraph added to the central column with jQuery.</p>');

There's a similar function called prepend that adds things to the start rather than the end.

There's one other thing you should probably think about when building this course format. What about resources and activities that don't really have their own page? One example would be labels. Another would be files (e.g. Word or Powerpoint) that are set to force download, rather than displaying the description in their own page.

 
Average of ratings: -
Brian
Re: Examples of Blocks that output to Central Column
Group Particularly helpful Moodlers

Good points all Alex - I will look for a YUI equivalent.  If driven by PHP that will make access to the Moodle course and activity sequence easier (and if not, I guess it is still possible).

Resources & activities that don't have their own page will still render really nicely with course/view.php anyway, so it is just a matter of building the right links, and if the user gets confused there is always the nav block on the left / right.

To start with it won't look as cool as your page, but I guess I had better start with "working" wink

 
Average of ratings: -