Overriding renderers

Renderers are way in which you can change the look and feel of a Totara site.

A renderer is a PHP function that returns a string containing HTML to be displayed. This sometimes creates a context variable which is fed into a mustache template (returning the result of the template).

Overwriting renderers

You can overwrite rendered when the level of changes required exceed the functionality available via CSS and mustache templates (or otherwise not available).

There should be a PHP class that extends the next renderer for this component up in your theme chain e.g. if your theme "b" is a child of theme "a", then class theme_b_core_renderer should extend theme_a_core_renderer. If your parent theme does not extend the required component then you should extend the core renderer e.g. if theme "a" doesn't extend core_renderer, then the child theme "b" will need to extend core_renderer (as the class theme_a_core_renderer will not exist).

Renderer locations

renderer.php

The existing one is in a renderer.php file in the component or outputrenderers.php.

The overwritten renderer should be placed in theme/<themename>/renderer.php and inherit from the previous class in the theme chain, using require_once to ensure that the parent class is available.

/classes/*

The existing one is in /classes/*

These should be placed in theme/<themename>/classes/*

Upgrades

When there are changes to core (or core theme) renderers, these will be mentioned in their respective upgrade.txt files (e.g. changes to mod/foo/renderer.php will be documented in mod/foo/upgrade.txt). We recommend that you keep an eye on these files to ensure that your templates are working as expected. These files will also contain other useful information when upgrading your site.