[3.8.3+] overriding core_course_renderer in moove theme

[3.8.3+] overriding core_course_renderer in moove theme

by tim st.clair -
Number of replies: 4
Picture of Plugin developers

In /course/index.php there is

$courserenderer = $PAGE->get_renderer('core', 'course');
$content = $courserenderer->course_category($categoryid);

so I want to override core_course_renderer in the theme (moove).

I added a renderers.php in the moove theme folder. In is, in its entirety:

<?php
require_once($CFG->dirroot .'/course/renderer.php');
class theme_moove_core_course_renderer extends core_course_renderer {
    public function course_category($category) {
        return 'i am a banana';
    }
}

I expected that when I hit the course index page I'd be told that I am a banana. But I see the standard page. What do I have to do to override this renderer from a theme?

Average of ratings: -
In reply to tim st.clair

Re: [3.8.3+] overriding core_course_renderer in moove theme

by Vitaly Potenko -
Picture of Core developers Picture of Plugin developers
Make use of classes autoloading in Moodle. Create a file with the following path - {your_theme}/classes/output/core/course_renderer.php.
Start with the following class there:

namespace theme_{your_theme}\output\core;
class course_renderer extends \core_course_renderer {
}
Start overriding the methods.

You can find more info about the classes autoloading feature here: https://docs.moodle.org/dev/Automatic_class_loading
One more importnat note: purge the caches after you add any new class for autoloading to allow Moodle to load it for you.
Average of ratings: Useful (2)
In reply to Vitaly Potenko

Re: [3.8.3+] overriding core_course_renderer in moove theme

by tim st.clair -
Picture of Plugin developers
Aah yes, I had the renderer file in the wrong spot. Thanks!
In reply to Vitaly Potenko

Re: [3.8.3+] overriding core_course_renderer in moove theme

by LMS Doctor -
@Vitaly How should I implement it in the theme if I want to override format_section_renderer_base located in course/format/renderer.php ... I need to adjust some of the methods from a custom theme.

I tried: mytheme/classes/output/core/format/section_renderer_base.php without success.

namespace theme_childhelpline\output\core\format;

class section_renderer_base extends \format_section_renderer_base {

}



In reply to LMS Doctor

Re: [3.8.3+] overriding core_course_renderer in moove theme

by Vitaly Potenko -
Picture of Core developers Picture of Plugin developers
Sorry for the late reply, I think this would work:
mytheme/classes/output/format_section_renderer.php
and inside you have

namespace mytheme\output;
require_once($CFG->dirroot.'/course/format/renderer.php');
class format_section_renderer extends \format_section_renderer_base {}
I've not checked it though, but that's what I would start with.