Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Output renderers: Difference between revisions

From MoodleDocs
No edit summary
Line 3: Line 3:
|name = Output renderers
|name = Output renderers
|state = Specification
|state = Specification
|tracker = MDL-20204
|tracker = MDL-21235
|discussion = n/a
|discussion = n/a
|assignee = [[User:Petr Škoda (škoďák)|Petr Škoda (škoďák)]] + [[User:David Mudrak|David Mudrak]] + feedback and ideas from other developers
|assignee = [[User:Petr Škoda (škoďák)|Petr Škoda (škoďák)]] + [[User:David Mudrak|David Mudrak]] + feedback and ideas from other developers

Revision as of 18:33, 7 January 2010

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.

Output renderers
Project state Specification
Tracker issue MDL-21235
Discussion n/a
Assignee Petr Škoda (škoďák) + David Mudrak + feedback and ideas from other developers

Moodle 2.0


Goals

  • stable API
  • easy to use
  • easy to customise via themes

Renderers

Output renderer is a class with collection of methods that handle rendering of visual aspects of Moodle pages, emails, html export, etc. In 1.9 general output related functions were located in weblib.php and modules stored rendering code in lib.php, locallib.php, view.php, etc.

Output renderer instances are obtained through moodle_page::get_renderer($component, $subtype = null, $target = null) method. Current core_renderer is available through the global $OUTPUT variable, please note this global should not be used in low level APIs.

Renderer targets

renderer_base

Abstract class every other renderer must extend. Renderer base implements basic methods and support for renderer dispatching. The most important method is render(), it is using class name of the widget passed in first parameter to find fine correct protected rendering method (widget rendering methods have render_ prefix.

core_renderer

For example user avatar rendering involves following methods and classes: class core_renderer extends renderer_base {

 // ...
 public function render(widget $widget) {
    // calls $this->render_user_image($widget) when parameter with class user_image submitted 
 }
 protected function render_user_image(user_image $user_image) {
   // returns html markup for user avatar
 }
 public function user_image($userrecord, array $options=null) {
   // helper method that constructs $user_image widget and calls $this->render
 }
 // ...

}

class user_image extends widget {

 public $userrecord;
 public $options;
 public function __construct($userrecord, array $options=null) {
     // ...
 }

}

core_renderer_cli

Core subsystem renderers

Plugin renderers

Bootstrap renderer

Theme customisations

Theme renderers

HTML output

See also