How to override content class from core_courseformat\output\local\content

How to override content class from core_courseformat\output\local\content

by Ivo Valkov -
Number of replies: 4

Hi guys,

I need to override the export_for_template method from core_courseformat\output\local\content in my custom theme so I can provide some custom data to the mustache template.

I did the following but it didn't work:

  1. I created a content.php file in ROOT/theme/MY_THEME/classes/output/core_courseformat/local
  2. In the content.php file I have the following code:
    	
namespace theme_MY_THEME\output\core_courseformat\local;
defined('MOODLE_INTERNAL') || die();

use core\output\named_templatable;
use core_courseformat\base as course_format;
use course_modinfo;
use renderable;

class content extends \core_courseformat\output\local\content {

  public function export_for_template(\renderer_base $output) {
    ...
  }
}
      
    

But for some reason it does not work.

Could you please let me know what I'm doing wrong? Thanks.

Average of ratings: -
In reply to Ivo Valkov

Re: How to override content class from core_courseformat\output\local\content

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
Because of the Course Format API changes including autoloading in M4.0, it is not possible for a theme to override these course format classes. Only a course format can do that - but I've not tried to see if you can have a child course format of 'Topics' etc.
In reply to Gareth J Barnard

Re: How to override content class from core_courseformat\output\local\content

by Ivo Valkov -
Thank for the reply Gareth!

Alright, but then how am I supposed to implement the Theme Settings in the mustache templates? Is there a way to provide a theme setting in the content.mustache file for example, apart from overriding the export_for_template method (which is currently not possible)?

Being able to provide the Theme Settings in the mustache templates is crucial for every theme developer so I hope there will be a solution, either now or in a future Moodle release.

Thanks again, Gareth!
In reply to Ivo Valkov

Re: How to override content class from core_courseformat\output\local\content

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

As I said, you can't. If you want to learn more about one of the changes that helps understanding in this area, then please see MDL-73679. There might be another tracker asking for theme's to be able to override the 'export' element (the actual mustache, I think can be). If not and you raise an issue, then please do post a link here to attract discussion and possibly votes.

G