Moodle – extended course format render from theme

How to customise course format from theme. Example on course format grid.

In your theme folder create file php in folder ‘class’.

Copy to new file code from original class render course format (renderer.php)
Change extended class name to class name original class render course format

//example
class format_grid_renderer extends \format_grid_renderer

Add require_once with relevant path to original render.php

Change parent::__construct() in public function __construct()

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

class format_grid_renderer extends \format_grid_renderer {

protected $section0attop; // Boolean to state if section zero is at the top (true) or in the grid (false).
protected $courseformat; // Our course format object as defined in lib.php.
private $settings; // Settings array.
private $shadeboxshownarray = array(); // Value of 1 = not shown, value of 2 = shown - to reduce ambiguity in JS.
private $portable = 0; // 1 = mobile, 2 = tablet.
private $localmashalenabled = false; // 1 = mobile, 2 = tablet.

/**
* Constructor method, calls the parent constructor - MDL-21097
*
*
@param moodle_page $page
*
@param string $target one of rendering target constants
*/
public function __construct($page, $target) {
parent::__construct($page, $target);
$this->courseformat = course_get_format($page->course);
$this->settings = $this->courseformat->get_settings();
$this->section0attop = $this->courseformat->is_section0_attop();

$plugins = \core_plugin_manager::instance()->get_plugins_of_type('local');
foreach ($plugins as $plugin) {
if($plugin->name == 'mashal'){
$this->localmashalenabled = true;
}
}

In file core_render.php into theme add require_once with path to new file

require_once($CFG->dirroot . '/theme/mashal/classes/grid_renderer_custom.php');

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.