Making a Block Available Only on Course Home Page

Making a Block Available Only on Course Home Page

by Jeff Geronimo -
Number of replies: 4

Hi all,

I thought I'd reach out to the developer community for some advice regarding a project I'm working on. A department at my college wants a piece of HTML code (a "widget") to appear on the front page of every new and existing Moodle course, and I'm wondering what strategy might work best to accomplish this. My first thought was to add a new HTML block to the front page of our Moodle site, embed the HTML code, and make it available site-wide on every page, but that means the block would be viewable on every single page which can be a nuisance. The widget should only appear on the course homepage and faculty should have the option of removing it if they wish.

Does anyone have any ideas on the best (and easiest) way to accomplish something like this? Maybe there's a way to do a modification of the existing core HTML block and/or some database hacks? I'd like to avoid having to scope out extra project time to build a block from scratch (unless that happens to be the best option). The information in this documentation is promising, but appears to require an actual block to be built from scratch for it to work: http://docs.moodle.org/23/en/Block_layout. Since the HTML block can be configured in so many different ways by each user, there doesn't seem to be any one unique configuration I could use.

Thanks for any suggestions anyone might have!

-Jeff

Average of ratings: -
In reply to Jeff Geronimo

Re: Making a Block Available Only on Course Home Page

by Darko Miletić -

The solution in your case would be to:

Create a clone of HTML block plugin that displays whatever needs to be displayed.

Enable that block to be added only to course front-pages

Alter your config.php to include this block in the list of default blocks added to every newly created course.

$CFG->defaultblocks_override = '[list of blocks], [your custom block name]';


Than manually add the block to the existing courses and you are set.

In reply to Darko Miletić

Re: Making a Block Available Only on Course Home Page

by Jeff Geronimo -

Darko,

Thanks so much for your suggested solution. Just a quick follow-up question: if I clone the HTML block, embed my code, add it to the front page of our Moodle site, and then enable it to be added only to course front pages, would the same exact block with the custom HTML code appear if I call it in the config.php file? It was my assumption that because the HTML block can be unique for each user who adds it to his/her course, this would mean that calling the block as part of the default blocks in config.php would simply just add a generic HTML block without the custom code I want it to use. If it will indeed add the HTML block with my custom code, then this will work perfectly! Let me know your thoughts.

Thanks,

Jeff

In reply to Jeff Geronimo

Re: Making a Block Available Only on Course Home Page

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

A better solution that Darko's

  1. Add the block to the front page.
  2. Set it to appear on absolutely any page throughout the site.
  3. Go to any course.
  4. Edit the block settings, and change the setting to 'Any type of course main page'. (That seeing is not available when you are looking at the site front page, but it is when you are looking at a course page.)
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Making a Block Available Only on Course Home Page

by Jeff Geronimo -

Tim,

Thanks for proposing your solution, too. Would this solution also allow faculty to remove the block from their individual courses if they wish to do so without potentially deleting the same block from all courses? Your solution appears to work, but it seems like I'm the only one able to remove the block and I want to give faculty the option to remove it from their courses as well at a course by course basis without deleting it from the entire site.

Please let me know your thoughts on this.

Thanks,

Jeff