Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: Output API.

Obsolete:Output API: Difference between revisions

From MoodleDocs
(Creating the Output API page)
 
Line 5: Line 5:


== Components ==
== Components ==
Components in the Output API are classes that represent elements to be output. They do not contain any code for outputting anything, but they contain rich meta-data that is used by the Renderers to generate output. Some of the key aspects of components are outlined here:
* Components do not have defined constructors. Passing arguments to the default constructor will not do anything useful.
* Components consist mainly of variables with sensible defaults, and a prepare() method which makes use of these variables to setup other defaults prior to rendering.
* The prepare() method always behaves the same way, regardless of which renderer is used. This ensures consistency of the component's variables.
* Additional "shortcut" methods are sometimes added to provide a more high-level API to developers.
=== moodle_html_component ===
This is the base class for all output components. It is not declared as abstract, because you could actually use it to instantiate a basic component. However, almost all rendering functions will expect a sub-class of this class as a parameter, so instantiating it is unlikely to be very useful.
This class basically holds data and useful functions that can apply to any component, such as id, classes, style, alt and title (HTML attributes valid for any XHTML element). It also handles the collection and setting up of component_actions, which are described below. Refer to the class' PHP docs for details on variables and functions.
This class also defines a function for generating unique HTML ids for components that require one, and holds a static array for generated ids to prevent duplication.


== Renderers ==
== Renderers ==

Revision as of 08:10, 10 August 2009

Moodle 2.0


Note: This article is a work in progress. Please use the page comments or an appropriate moodle.org forum for any recommendations/suggestions for improvement.


This page describes the Output API for Moodle 2.0. It works closely with the Page API, so you may want to refer to that documentation as well.

Components

Components in the Output API are classes that represent elements to be output. They do not contain any code for outputting anything, but they contain rich meta-data that is used by the Renderers to generate output. Some of the key aspects of components are outlined here:

  • Components do not have defined constructors. Passing arguments to the default constructor will not do anything useful.
  • Components consist mainly of variables with sensible defaults, and a prepare() method which makes use of these variables to setup other defaults prior to rendering.
  • The prepare() method always behaves the same way, regardless of which renderer is used. This ensures consistency of the component's variables.
  • Additional "shortcut" methods are sometimes added to provide a more high-level API to developers.

moodle_html_component

This is the base class for all output components. It is not declared as abstract, because you could actually use it to instantiate a basic component. However, almost all rendering functions will expect a sub-class of this class as a parameter, so instantiating it is unlikely to be very useful.

This class basically holds data and useful functions that can apply to any component, such as id, classes, style, alt and title (HTML attributes valid for any XHTML element). It also handles the collection and setting up of component_actions, which are described below. Refer to the class' PHP docs for details on variables and functions.

This class also defines a function for generating unique HTML ids for components that require one, and holds a static array for generated ids to prevent duplication.

Renderers

Pix finders

Actions

Factories

Theme Config

XHTML Container Stack

Miscellaneous functions