Course Format Topics Renderer override not working?

Course Format Topics Renderer override not working?

by I V -
Number of replies: 7

Moodle: v3.3.1

Theme: Mytheme (cloned from Boost for template/layout, but using own styles)

Hi there,

I'm trying to change the way Course listing page is at the moment. It uses Topic format where all topics/modules of a course are listed first as links followed by a new page where each section's individual activities/resources appear.

I'd like to 

- Move the "Forums or General" section on the right with other blocks 

- Add some of our own CSS classes in the markup to style the Course Listing page as per our theme

The theme config has the below renderer set and I also have a core_renderer in my theme working perfectly fine

$THEME->rendererfactory = 'theme_overridden_renderer_factory';
https://moodle.org/mod/forum/discuss.php?d=229890 is somewhat similar to what I'm trying to do but not sure if it's the correct way & what should be the folder/naming convention?

As per the above link, rather than extending `format_section_renderer_base`, it's best to extend `format_topics_renderer` as that's the format being used. So have followed that path but to no success.

This is what I have so far:
theme
  mytheme
     classes
        output
           core
              course_format_topics_renderer.php
namespace theme_mytheme\output\core;

defined('MOODLE_INTERNAL') || die();

use moodle_url;
require_once($CFG->dirroot.'/course/format/topics/renderer.php');

class course_format_topics_renderer extends \format_topics_renderer
{

public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) { ... existing code borrowed ... custom code }
public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
global $PAGE; ... existing code borrowed ... custom code } }


But this doesn't work as it has no effect whatsoever on the Course listing pages.

I think if I manage to override the below functions in my theme renderer somehow, I can then manipulate the Course Listing page completely.

format_topics_renderer::print_single_section_page
format_topics_renderer::print_multiple_section_page

Any thoughts or guidance in this direction will be appreciated?


Thanks in advance!

Average of ratings: -
In reply to I V

Re: Course Format Topics Renderer override not working?

by I V -

Any suggestions at all?

In reply to I V

Re: Course Format Topics Renderer override not working?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
In reply to Gareth J Barnard

Re: Course Format Topics Renderer override not working?

by I V -

Thanks Gareth, that's helpful! Will take a close look and see if there are more pointers I can borrow. In the meanwhile, I did manage to get something working. Please see my response below.

In reply to I V

Re: Course Format Topics Renderer override not working?

by Dave Emsley -

Hi Ishani,

Just struggling with this myself but shouldn't your class begin with your theme name?  Mine is....

class theme_mytheme_course_renderer extends \core_course_renderer {
Or is that catered for within the "namespace"?


Hope this is useful. Dave
In reply to Dave Emsley

Re: Course Format Topics Renderer override not working?

by I V -

Thanks for your response Dave!

I have recently managed to make slight progress. Will post here, incase if that's helpful to anyone

My theme config file has this

$THEME->rendererfactory = 'theme_overridden_renderer_factory';
Then I'm extending lib/outputrenderers.php AND course/format/topics/renderer.php in the same file

theme > mytheme > classes > output > core_renderer.php

namespace theme_mytheme\output;

use coding_exception;
use html_writer;
use tabobject;
... n so on

defined('MOODLE_INTERNAL') || die;

/**
* Renderers to align Moodle's HTML with that expected by Bootstrap
*
* @package theme_mytheme
*/

class core_renderer extends \core_renderer { // Copy functions from core rendered but with my own custom code // For Ex public function header() { // my custom code }
} // In the same file at the end of this class, I'm extending another renderer require_once($CFG->dirroot.'/course/format/topics/renderer.php'); class format_topics_renderer extends \format_topics_renderer { // we can then modify topics_renderer OR format_renderer functions like this protected function section_activity_summary($section, $course, $mods) { // Parent code with own custom code } }

Average of ratings: Useful (2)
In reply to I V

Re: Course Format Topics Renderer override not working?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

RE: "Then I'm extending lib/outputrenderers.php AND course/format/topics/renderer.php in the same file" = don't.

Average of ratings: Useful (1)
In reply to Gareth J Barnard

Re: Course Format Topics Renderer override not working?

by I V -

Why not? Is there a specific reason you wouldn't advocate this way of doing things?

It sure is the way some of the core files are built as well where you have multiple classes in your renderer. I have seen this way of extending in your theme in few forums, so doesn't seem like a non upgrade safe way of doing things & it works.