<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Simontite</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Simontite"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/Special:Contributions/Simontite"/>
	<updated>2026-06-07T22:45:17Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Output_API&amp;diff=34571</id>
		<title>Output API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Output_API&amp;diff=34571"/>
		<updated>2012-07-26T08:35:59Z</updated>

		<summary type="html">&lt;p&gt;Simontite: /* moodle_action_icon */ Fix link to example usage and output&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{obsolete}}&lt;br /&gt;
See [[Migrating_your_code_to_the_2.0_rendering_API#Outputting_HTML_specific_to_your_module|this page]] for more up-to-date information. --[[User:David Mudrak|David Mudrak]] 22:16, 23 August 2009 (UTC)&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Components ==&lt;br /&gt;
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:&lt;br /&gt;
* Components do not have defined constructors with arguments. Passing arguments to the default constructor will not do anything useful.&lt;br /&gt;
* Some components have a constructor which is used exclusively to instantiate object member variables.&lt;br /&gt;
* 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.&lt;br /&gt;
* The prepare() method always behaves the same way, regardless of which renderer is used. This ensures consistency of the component&#039;s variables.&lt;br /&gt;
* Additional &amp;quot;shortcut&amp;quot; methods are sometimes added to provide a more high-level API to developers.&lt;br /&gt;
&lt;br /&gt;
=== moodle_html_component ===&lt;br /&gt;
*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.&lt;br /&gt;
*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&#039; PHP docs for details on variables and functions.&lt;br /&gt;
*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.&lt;br /&gt;
*A set_label($text, $for=null) is defined, with the first argument accepting either a string or a html_label component, in which latter case the second argument is ignored. If the component does not have an $id value, one will be generated and assigned to the label&#039;s $for value unless a html_label object is given as the $text argument. For this reason, if you explicitly set a component&#039;s $id value, make sure set_label() is called after you set that value.&lt;br /&gt;
&lt;br /&gt;
=== HTML low-level components ===&lt;br /&gt;
This list of components replicate basic HTML elements. They are prefixed with html_ to make it clear that they are the basic building blocks of the output API.&lt;br /&gt;
&lt;br /&gt;
==== html_label ====&lt;br /&gt;
*Many HTML elements may have a label (input fields, dropdowns etc.). Some rendering functions look for this label and render it accordingly.&lt;br /&gt;
*html_label requires a $text value, and should be given a $for value for accessibility reasons. It is rendered ultimately by $OUTPUT-&amp;gt;label(html_label $label).&lt;br /&gt;
&lt;br /&gt;
==== html_field ====&lt;br /&gt;
*Represents a HTML input field. Can be used to output any input type, although some of its variables only apply to some types (e.g. maxlength only applies to text inputs).&lt;br /&gt;
*It has a shortcut method for preparing a text input: make_text($name, $value, $alt, $maxlength).&lt;br /&gt;
&lt;br /&gt;
==== html_button ====&lt;br /&gt;
*Represents a HTML button, which may be rendered in many different ways, though by default it is rendered as an input field of type &amp;quot;button&amp;quot;.&lt;br /&gt;
*Requires a $text value (by default used as the HTML &amp;quot;value&amp;quot; attribute)&lt;br /&gt;
&lt;br /&gt;
==== html_link ====&lt;br /&gt;
*Represents a link, by default rendered by the $OUTPUT-&amp;gt;link() function as HTML: &lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;$url&amp;quot;&amp;gt;$text&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== html_image ====&lt;br /&gt;
*Simple class representing an image, rendered by $OUTPUT-&amp;gt;image().&lt;br /&gt;
*The $alt variable is set to HTML_ATTR_EMPTY by default. This constant is interpreted by the renderer as an attribute with an empty string as a value. If you use an actual empty string, the attribute will not be output at all, which would break XHTML strict for the &amp;lt;img/&amp;gt; tag.&lt;br /&gt;
&lt;br /&gt;
==== html_form ====&lt;br /&gt;
*This component represents a form &#039;wrapper&#039; with an optional html_button object. You can use $OUTPUT-&amp;gt;form($form, $contents) to output a form with any HTML you want within it.&lt;br /&gt;
*The object requires a $url value, which can either be a string or a moodle_url object. In the prepare() method, this variable will be converted to a moodle_url.&lt;br /&gt;
*If the $method &amp;quot;post&amp;quot; is used, the sesskey param will be added automatically&lt;br /&gt;
*You can use the $params array to specify hidden inputs, but it will be ignored if you give a moodle_url as the $url value (because moodle_urls include query params).&lt;br /&gt;
*This object is also used by the $OUTPUT-&amp;gt;button($formwithbutton) and the $OUTPUT-&amp;gt;confirm($message, $formcontinue, $formcancel) methods.&lt;br /&gt;
&lt;br /&gt;
==== html_list ====&lt;br /&gt;
*Represents a HTML nested list.&lt;br /&gt;
*Has a load_data($tree, $level=0) recursive method which take a nested array and stores instantiated html_list_item objects in the $items array.&lt;br /&gt;
*CSS classes are automatically added to each element in the list, to allow for custom styling.&lt;br /&gt;
*This is rendered by $OUTPUT-&amp;gt;htmllist($list) as a &amp;lt;nowiki&amp;gt;&amp;lt;ul&amp;gt; or &amp;lt;ol&amp;gt;&amp;lt;/nowiki&amp;gt; element, but could be used to output nav menus etc. by yet unwritten output methods.&lt;br /&gt;
*Use the $type variable to specify if the list should be ordered or unordered.&lt;br /&gt;
&lt;br /&gt;
==== html_list_item ====&lt;br /&gt;
*Represents a list item used by the html_list component. Only has a $value variable, but also benefits from all other variables and methods of the moodle_html_component base class.&lt;br /&gt;
&lt;br /&gt;
==== html_table ====&lt;br /&gt;
*Represents a HTML table with data&lt;br /&gt;
*Is intended to replace the old flexible_table class&lt;br /&gt;
*The $data array either holds an associate array of arrays representing rows and cells, or it can be set up with html_table_row and html_table_cell objects, for finer control over the look and layout of the table cells.&lt;br /&gt;
*In the html_writer::table($table) method, the $data array&#039;s contents are converted into html_table_row and html_table_cell objects if they are not already of that type.&lt;br /&gt;
&lt;br /&gt;
==== html_table_row ====&lt;br /&gt;
*A simple component holding an array of html_table_cell objects.&lt;br /&gt;
&lt;br /&gt;
==== html_table_cell ====&lt;br /&gt;
*This represents a table cell, and is aggregated by a html_table_row object, itself aggregated by html_table.&lt;br /&gt;
*This component&#039;s variables mirror those of the XHTML &amp;lt;nowiki&amp;gt;&amp;lt;td&amp;gt; or &amp;lt;th&amp;gt;&amp;lt;/nowiki&amp;gt; elements (differentiated by the $header boolean)&lt;br /&gt;
&lt;br /&gt;
==== html_select ====&lt;br /&gt;
*This object is by far the most complex HTML component in Moodle. It represents any element that presents the user with a choice. This includes:&lt;br /&gt;
*#A dropdown menu (&amp;lt;nowiki&amp;gt;&amp;lt;select&amp;gt; tag&amp;lt;/nowiki&amp;gt;), optionally with automatic redirection upon selection of an option&lt;br /&gt;
*#A set of radio buttons (&amp;lt;nowiki&amp;gt;&amp;lt;input type=&amp;quot;radio&amp;quot; /&amp;gt; tag&amp;lt;/nowiki&amp;gt;)&lt;br /&gt;
*#A set of checkboxes (&amp;lt;nowiki&amp;gt;&amp;lt;input type=&amp;quot;checkbox&amp;quot; /&amp;gt; tag&amp;lt;/nowiki&amp;gt;)&lt;br /&gt;
*However, remember that the HTML tags given above are the default rendering of a html_select object. This object can hold so much data that it could be rendered in a multiple of different ways, not necessarily using these traditional HTML tags.&lt;br /&gt;
*This class has a special method initialise_options() which converts the given $options into html_select_optgroup and html_select_option objects. This allows you to override these options&#039; defaults and add style, classes and component_action objects before the object is sent to the renderer.&lt;br /&gt;
&lt;br /&gt;
*Some examples follow:&lt;br /&gt;
&lt;br /&gt;
===== Basic example =====&lt;br /&gt;
The following will output a basic drop-down menu, ready to be included in a form:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$select = html_select::make(array(&#039;1&#039; =&amp;gt; &#039;Value 1&#039;, &#039;2&#039; =&amp;gt; &#039;Value 2&#039;), &#039;choice1&#039;, &#039;2&#039;));&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;select id=&amp;quot;menuchoice1&amp;quot; class=&amp;quot;menuchoice1 select&amp;quot; name=&amp;quot;choice1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;Choose...&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;Value 1&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option selected=&amp;quot;selected&amp;quot; value=&amp;quot;2&amp;quot;&amp;gt;Value 2&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note that a default &amp;quot;Choose...&amp;quot; option with a value of 0 is added to the menu. To remove this, follow the next example:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$select-&amp;gt;nothinglabel = false;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This will remove the default option completely.&lt;br /&gt;
&lt;br /&gt;
===== Nested menus =====&lt;br /&gt;
You can also render a menu with one level of nesting, rendered as a dropdown with optgroups. You just need to do two things to achieve that:&lt;br /&gt;
#Specify $select-&amp;gt;nested = true&lt;br /&gt;
#Either:&lt;br /&gt;
#*$select-&amp;gt;load_data($flatarray), which requires a rather cryptic syntax with double-dashes for optgroups&lt;br /&gt;
#*$select-&amp;gt;load_data($nestedarray), the first level&#039;s keys are the names of the optgroups, their arrays are the options&#039; value=&amp;gt;label pairs.&lt;br /&gt;
#*Prepare the data directly as html_select_optgroup and html_select_option objects. This method requires more code but less debugging because it is a lot less brittle than a string-based syntax, and it allows more customised classes, JS actions etc. on each individual option.&lt;br /&gt;
&lt;br /&gt;
The preferred method is the second one in the majority of cases, because it is easy to setup and debug. The first method should be avoided and will not be demonstrated here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Method 2:&lt;br /&gt;
$options = array(&#039;Group1&#039; =&amp;gt; array(&#039;value1&#039; =&amp;gt; &#039;Option 1&#039;, &#039;value2&#039; =&amp;gt; &#039;Option 2&#039;), &#039;Group2&#039; =&amp;gt; array(&#039;value3&#039; =&amp;gt; &#039;Option 3&#039;, &#039;value4&#039; =&amp;gt; &#039;Option 4&#039;));&lt;br /&gt;
$select = html_select::make($options, &#039;choice1&#039;, &#039;value1&#039;);&lt;br /&gt;
$select-&amp;gt;nested = true;&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&lt;br /&gt;
// Method 3:&lt;br /&gt;
$optgroup1 = new html_select_optgroup();&lt;br /&gt;
$optgroup2 = new html_select_optgroup();&lt;br /&gt;
$optgroup1-&amp;gt;text = &#039;Group1&#039;;&lt;br /&gt;
$optgroup2-&amp;gt;text = &#039;Group2&#039;;&lt;br /&gt;
&lt;br /&gt;
$option1 = new html_select_option();&lt;br /&gt;
$option2 = new html_select_option();&lt;br /&gt;
$option3 = new html_select_option();&lt;br /&gt;
$option4 = new html_select_option();&lt;br /&gt;
&lt;br /&gt;
$option1-&amp;gt;text = &#039;Option 1&#039;;&lt;br /&gt;
$option1-&amp;gt;value = &#039;value1&#039;;&lt;br /&gt;
$option2-&amp;gt;text = &#039;Option 2&#039;;&lt;br /&gt;
$option2-&amp;gt;value = &#039;value2&#039;;&lt;br /&gt;
$option3-&amp;gt;text = &#039;Option 3&#039;;&lt;br /&gt;
$option3-&amp;gt;value = &#039;value3&#039;;&lt;br /&gt;
$option4-&amp;gt;text = &#039;Option 4&#039;;&lt;br /&gt;
$option4-&amp;gt;value = &#039;value4&#039;;&lt;br /&gt;
&lt;br /&gt;
$optgroup1-&amp;gt;options = array($option1, $option2);&lt;br /&gt;
$optgroup2-&amp;gt;options = array($option3, $option4);&lt;br /&gt;
&lt;br /&gt;
$select = html_select::make(array($optgroup1, $optgroup2), &#039;choice1&#039;, &#039;value1&#039;);&lt;br /&gt;
$select-&amp;gt;nested = true;&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Both these methods Output:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;select id=&amp;quot;menuchoice1&amp;quot; class=&amp;quot;menuchoice1 select&amp;quot; name=&amp;quot;choice1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;optgroup label=&amp;quot;Group1&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;option selected=&amp;quot;selected&amp;quot; value=&amp;quot;value1&amp;quot;&amp;gt;Option 1&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;option value=&amp;quot;value2&amp;quot;&amp;gt;Option 2&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;/optgroup&amp;gt;&lt;br /&gt;
  &amp;lt;optgroup label=&amp;quot;Group2&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;option value=&amp;quot;value3&amp;quot;&amp;gt;Option 3&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;option value=&amp;quot;value4&amp;quot;&amp;gt;Option 4&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;/optgroup&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Although the last method looks very code-intensive, most of it would obviously be reduced using foreach loops, and it allows for much more customisation of the components.&lt;br /&gt;
&lt;br /&gt;
===== Yes/No menu =====&lt;br /&gt;
A common use case is to print a Yes/No menu. This could be output as two radio buttons, but it is sometimes output as a menu. The two cases are demonstrated here:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$select = html_select::make_yes_no(&#039;choice1&#039;, 1);&lt;br /&gt;
$select-&amp;gt;nothinglabel = false; // Don&#039;t forget to do this, or the &amp;quot;Choose...&amp;quot; option will appear and have the same value as the &amp;quot;No&amp;quot; option!&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;select id=&amp;quot;menuchoice1&amp;quot; class=&amp;quot;menuchoice1 select&amp;quot; name=&amp;quot;choice1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;No&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option selected=&amp;quot;selected&amp;quot; value=&amp;quot;1&amp;quot;&amp;gt;Yes&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Radio buttons:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$select-&amp;gt;rendertype = &#039;radio&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;span class=&amp;quot;radiogroup choice1 rb0&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label for=&amp;quot;html_select_option-b4d4bd&amp;quot;&amp;gt;No&amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input id=&amp;quot;html_select_option-b4d4bd&amp;quot; type=&amp;quot;radio&amp;quot; name=&amp;quot;choice1&amp;quot; value=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;radiogroup choice1 rb1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label for=&amp;quot;html_select_option-1eaa39&amp;quot;&amp;gt;Yes&amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input id=&amp;quot;html_select_option-1eaa39&amp;quot; type=&amp;quot;radio&amp;quot; checked=&amp;quot;checked&amp;quot; name=&amp;quot;choice1&amp;quot; value=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, in many cases it is better to display a yes/no choice as a single checkbox. For this purpose, it is better to instantiate a single html_option object and pass it to $OUTPUT-&amp;gt;checkbox().&lt;br /&gt;
&lt;br /&gt;
===== Date/Time selectors =====&lt;br /&gt;
NOTE: This part of the API is under review&lt;br /&gt;
&lt;br /&gt;
The html_select object can be used to output date or time selectors. A shortcut method is provided for this purpose: make_time_selector($type, $currenttime, $step);&lt;br /&gt;
For more concise code, you can use the higher-level method make_time_selectors($selectors, $currentime, $step);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$dayselector = html_select::make_time_selector(&#039;days&#039;, &#039;myday&#039;, &#039;120308000&#039;);&lt;br /&gt;
$monthselector = html_select::make_time_selector(&#039;months&#039;, &#039;mymonth&#039;, &#039;120308000&#039;);&lt;br /&gt;
$yearselector = html_select::make_time_selector(&#039;years&#039;, &#039;myyear&#039;, &#039;120308000&#039;);&lt;br /&gt;
$hourselector = html_select::make_time_selector(&#039;hours&#039;, &#039;myhour&#039;, &#039;120308000&#039;);&lt;br /&gt;
$minuteselector = html_select::make_time_selector(&#039;minutes&#039;, &#039;myminute&#039;, &#039;120308000&#039;, 5);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($dayselector);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($monthselector);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($yearselector);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($hourselector);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($minuteselector);&lt;br /&gt;
&lt;br /&gt;
// OR&lt;br /&gt;
$selectors = html_select::make_time_selectors(array(&#039;days&#039; =&amp;gt; &#039;myday&#039;, &#039;months&#039; =&amp;gt; &#039;mymonth&#039;, &#039;years&#039; =&amp;gt; &#039;myyear&#039;, &#039;hours&#039; =&amp;gt; &#039;myhour&#039;, &#039;minutes&#039; =&amp;gt; &#039;myminute&#039;), &#039;120308000&#039;, 5);&lt;br /&gt;
foreach ($selectors as $select) {&lt;br /&gt;
    echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
[[Image:timeselectors.png]]&lt;br /&gt;
&lt;br /&gt;
===== Popup Forms =====&lt;br /&gt;
*This is a really bad name for a dropdown menu that redirects the user when an option is selected.&lt;br /&gt;
*html_select::make_popup_form() is a shortcut method for returning an object ready for rendering through $OUTPUT-&amp;gt;select()&lt;br /&gt;
*The basic premise of a &amp;quot;popup form&amp;quot; is that each option has as its value the URL to which the user should be redirected when that option is selected&lt;br /&gt;
*To simplify this process, make_popup_form() takes a URL as its first argument, and the name of a query param as the second. It is expected that the option values represent the value that will be assigned to this &amp;quot;variable&amp;quot; parameter.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$options = array(1 =&amp;gt; &#039;Page 1&#039;, 2 =&amp;gt; &#039;Page 2&#039;, 3 =&amp;gt; &#039;Page 3&#039;);&lt;br /&gt;
$select = html_select::make_popup_form(&#039;http://domain.com/index.php&#039;, &#039;id&#039;, $options, &#039;myform&#039;);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;form id=&amp;quot;myform&amp;quot; class=&amp;quot;popupform&amp;quot; action=&amp;quot;http://enterprise/cvs_moodle_head/course/jumpto.php&amp;quot; method=&amp;quot;get&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;JEgniUhzzx&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;select id=&amp;quot;myform_jump&amp;quot; class=&amp;quot;menujump select&amp;quot; name=&amp;quot;jump&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;Choose...&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/index.php?id=1&amp;quot;&amp;gt;Page 1&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/index.php?id=2&amp;quot;&amp;gt;Page 2&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/index.php?id=3&amp;quot;&amp;gt;Page 3&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
    &amp;lt;div id=&amp;quot;noscriptmyform&amp;quot; style=&amp;quot;display: none;&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Go&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sometimes you will need some of the URLs to have a different base, or to have more parameters that change between options. The best way to achieve this is demonstrated here:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$options = array(&#039;http://domain.com/index.php?id=1&#039; =&amp;gt; &#039;Page 1&#039;, &lt;br /&gt;
                 &#039;http://domain.com/otherpage/index.php?modid=1&#039; =&amp;gt; &#039;Page 2&#039;, &lt;br /&gt;
                 &#039;http://domain.com/index.php?id=1&amp;amp;othervar=2&#039; =&amp;gt; &#039;Page 3&#039;);&lt;br /&gt;
$select = html_select::make_popup_form(&#039;&#039;, &#039;&#039;, $options, &#039;myform&#039;);&lt;br /&gt;
$select-&amp;gt;override_option_values($options);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;form id=&amp;quot;myform&amp;quot; class=&amp;quot;popupform&amp;quot; action=&amp;quot;http://enterprise/cvs_moodle_head/course/jumpto.php&amp;quot; method=&amp;quot;get&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;JEgniUhzzx&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;select id=&amp;quot;myform_jump&amp;quot; class=&amp;quot;menujump select&amp;quot; name=&amp;quot;jump&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;Choose...&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/index.php?id=1&amp;quot;&amp;gt;Page 1&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/otherpage/index.php?modid=1&amp;quot;&amp;gt;Page 2&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/index.php?id=1&amp;amp;othervar=2&amp;quot;&amp;gt;Page 3&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
    &amp;lt;div id=&amp;quot;noscriptmyform&amp;quot; style=&amp;quot;display: none;&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Go&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== html_select_option ====&lt;br /&gt;
*This component represents an option&lt;br /&gt;
*It is not necessarily rendered as an &amp;lt;nowiki&amp;gt;&amp;lt;option&amp;gt;&amp;lt;/nowiki&amp;gt; tag, but can also be rendered as a radio or a checkbox&lt;br /&gt;
*It can be aggregated by html_select and html_select_optgroup, or used by itself in $OUTPUT-&amp;gt;checkbox($option, $name)&lt;br /&gt;
*It has a shortcut method for preparing a checkbox for output: make_checkbox($value, $selected, $label, $alt);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$checkbox = html_select_option::make_checkbox(&#039;1&#039;, false, get_string(&#039;donotask&#039;));&lt;br /&gt;
echo $OUTPUT-&amp;gt;checkbox($checkbox, &#039;donotask&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;checkbox donotask&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input id=&amp;quot;html_select_option-e7be90&amp;quot; type=&amp;quot;checkbox&amp;quot; name=&amp;quot;donotask&amp;quot; value=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;label for=&amp;quot;html_select_option-e7be90&amp;quot;&amp;gt;Do Not Ask&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
*Note that an ID is generated in this case even though no component_action was added. This is the default behaviour for the checkbox() method.&lt;br /&gt;
&lt;br /&gt;
==== html_select_optgroup ====&lt;br /&gt;
*This represents an option group, used only by html_select to group options together. It doesn&#039;t do anything particularly useful in itself apart from aggregating html_select_option objects and having a text value.&lt;br /&gt;
*It benefits from all the moodle_html_component variables and methods.&lt;br /&gt;
&lt;br /&gt;
=== Moodle components ===&lt;br /&gt;
The following components do not map exactly to HTML elements, so they are prefixed with moodle_.&lt;br /&gt;
&lt;br /&gt;
==== moodle_paging_bar ====&lt;br /&gt;
*Represents a paging bar used to navigate a large list of records like users, forum posts etc.&lt;br /&gt;
*Since 4 parameters are required, a shortcut function is provided: moodle_paging_bar::make($totalcount, $page, $perpage, $baseurl)&lt;br /&gt;
*The first page has a value of 0 but is displayed as 1, so remember this offset.&lt;br /&gt;
*If you have multiple paging bars on one page for different lists, set the $pagevar variable&lt;br /&gt;
*See [[Output_API#paging_bar]] for example usage and output&lt;br /&gt;
&lt;br /&gt;
==== moodle_user_picture ====&lt;br /&gt;
*Represents a user&#039;s picture to be output through $OUTPUT-&amp;gt;user_picture()&lt;br /&gt;
*Requires at least a $user object of stdClass with a minimum of data (id) and a $courseid&lt;br /&gt;
*If no specific image is given (as a html_image object), then the default image is loaded&lt;br /&gt;
*See [[Output_API#user_picture]] for example usage and output&lt;br /&gt;
&lt;br /&gt;
==== moodle_action_icon ====&lt;br /&gt;
*Simply put, this is a linked image.&lt;br /&gt;
*See [[Output_API#action_icon]] for example usage and output&lt;br /&gt;
&lt;br /&gt;
==== moodle_help_icon ====&lt;br /&gt;
See [[Output_API#help_icon]] For example usage. Replaces the old helpbutton() global function.&lt;br /&gt;
&lt;br /&gt;
== Renderers ==&lt;br /&gt;
=== renderer_base ===&lt;br /&gt;
* Simple base class for Moodle renderers.&lt;br /&gt;
* Tracks the xhtml_container_stack to use, which is passed in in the constructor.&lt;br /&gt;
* Also has methods to facilitate generating HTML output.&lt;br /&gt;
&lt;br /&gt;
==== output_tag methods ====&lt;br /&gt;
* Low-level functions for outputting specific HTML tags. &lt;br /&gt;
* For empty tags (with no content), use output_empty_tag&lt;br /&gt;
&lt;br /&gt;
==== pix_url ====&lt;br /&gt;
* Same as old_icon_url, but for old module icons&lt;br /&gt;
* The equivalent for &amp;quot;$CFG-&amp;gt;modpixpath/$mod/icon.gif&amp;quot; is mod_icon_url(&#039;icon&#039;, $mod)&lt;br /&gt;
&lt;br /&gt;
==== prepare_event_handlers(&amp;amp;$component) ====&lt;br /&gt;
* Used by rendering functions to prepare JS event listeners for components that may require it. &lt;br /&gt;
* All components that can receive user input should go through this method&lt;br /&gt;
&lt;br /&gt;
==== prepare_legacy_width_and_height($component) ====&lt;br /&gt;
* Returns the correct CSS for components that have the deprecated $height and/or $width attributes&lt;br /&gt;
&lt;br /&gt;
=== core_renderer ===&lt;br /&gt;
Since these functions are very well documented inline (phpdoc), I will only put examples here, without in-depth explanations.&lt;br /&gt;
&lt;br /&gt;
==== action_icon ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$icon = new moodle_action_icon();&lt;br /&gt;
$icon-&amp;gt;image-&amp;gt;src = $OUTPUT-&amp;gt;old_icon_url(&#039;moodlelogo&#039;);&lt;br /&gt;
$icon-&amp;gt;image-&amp;gt;alt = &#039;What is moodle?&#039;;&lt;br /&gt;
$icon-&amp;gt;link-&amp;gt;url = new moodle_url(&#039;http://domain.com/index.php&#039;);&lt;br /&gt;
$icon-&amp;gt;add_confirm_action(&#039;Are you sure?&#039;); // Optional. Equivalent to doing $icon-&amp;gt;link-&amp;gt;add_confirm_action(&#039;Are you sure?&#039;);&lt;br /&gt;
echo $OUTPUT-&amp;gt;action_icon($icon);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;a id=&amp;quot;html_link-2b4310&amp;quot; href=&amp;quot;http://domain.com/index.php&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;img class=&amp;quot;action-icon image&amp;quot; alt=&amp;quot;What is moodle?&amp;quot; src=&amp;quot;http://enterprise/cvs_moodle_head/pix/moodlelogo.gif&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/a&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
//&amp;lt;![CDATA[ &lt;br /&gt;
YAHOO.util.Event.addListener(&#039;html_link-2b4310&#039;, &#039;click&#039;, confirm_dialog, {&amp;quot;message&amp;quot;:&amp;quot;Are you sure?&amp;quot;});&lt;br /&gt;
//]]&amp;gt; &lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== box, box_start and box_end ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;box(&#039;A message of some kind&#039;);&lt;br /&gt;
// OR&lt;br /&gt;
echo $OUTPUT-&amp;gt;box_start();&lt;br /&gt;
echo &#039;A message of some kind&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;box_end();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;box generalbox&amp;quot;&amp;gt;A message of some kind&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== button ====&lt;br /&gt;
*Be aware that this method&#039;s signature requires a html_form component as its only argument. This form object must have a $button value (html_button)&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$form = new html_form();&lt;br /&gt;
$form-&amp;gt;url = new moodle_url(&#039;http://domain.com/index.php&#039;, array(&#039;id&#039; =&amp;gt; 3, &#039;userid&#039; =&amp;gt; 5));&lt;br /&gt;
$form-&amp;gt;button-&amp;gt;text = &#039;My account&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;button($form);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;singlebutton&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;form action=&amp;quot;http://domain.com/index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;div&amp;gt;&lt;br /&gt;
      &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;fXlccUgFTz&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;3&amp;quot; name=&amp;quot;id&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;5&amp;quot; name=&amp;quot;userid&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;My account&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== checkbox ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$checkbox = html_select_option::make_checkbox(&#039;1&#039;, false, get_string(&#039;donotask&#039;));&lt;br /&gt;
echo $OUTPUT-&amp;gt;checkbox($checkbox, &#039;donotask&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;checkbox donotask&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input id=&amp;quot;html_select_option-e7be90&amp;quot; type=&amp;quot;checkbox&amp;quot; name=&amp;quot;donotask&amp;quot; value=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;label for=&amp;quot;html_select_option-e7be90&amp;quot;&amp;gt;Do Not Ask&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== close_window_button ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;close_window_button();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;closewindow&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;singlebutton&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;form action=&amp;quot;http://enterprise/cvs_moodle_head/#&amp;quot; method=&amp;quot;get&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;div&amp;gt;&lt;br /&gt;
        &amp;lt;input id=&amp;quot;html_button-d35ffa&amp;quot; class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Close this window&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;/form&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
//&amp;lt;![CDATA[ &lt;br /&gt;
YAHOO.util.Event.addListener(&#039;html_button-d35ffa&#039;, &#039;click&#039;, close_window);&lt;br /&gt;
//]]&amp;gt; &lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== confirm ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;confirm(&#039;Are you sure?&#039;, &#039;/index.php?delete=1&#039;, &#039;/index.php&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;notice&amp;quot; class=&amp;quot;box generalbox&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;Are you sure?&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;buttons&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;singlebutton&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;form action=&amp;quot;http://enterprise/cvs_moodle_head/index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;fXlccUgFTz&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;1&amp;quot; name=&amp;quot;delete&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Yes&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
      &amp;lt;/form&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;singlebutton&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;form action=&amp;quot;http://enterprise/cvs_moodle_head/index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;fXlccUgFTz&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;No&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
      &amp;lt;/form&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== container, container_start and container_end ====&lt;br /&gt;
*Container differs from box in two ways:&lt;br /&gt;
*#It doesn&#039;t add default CSS classes (box adds a &amp;quot;box&amp;quot; class and a &amp;quot;generalbox&amp;quot; class unless the default is overridden)&lt;br /&gt;
*#It is stored in the XHTML stack as a &amp;quot;container&amp;quot;, not a &amp;quot;box&amp;quot;&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;container(&#039;A message of some kind&#039;, &#039;important&#039;, &#039;notice&#039;);&lt;br /&gt;
// OR&lt;br /&gt;
echo $OUTPUT-&amp;gt;container_start(&#039;important&#039;, &#039;notice&#039;);&lt;br /&gt;
echo &#039;A message of some kind&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;container_end();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;notice&amp;quot; class=&amp;quot;important&amp;quot;&amp;gt;A message of some kind&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== continue_button ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;continue_button(&#039;http://domain.com/index.php?id=2&amp;amp;userid=4&#039;);&lt;br /&gt;
// OR (preferred)&lt;br /&gt;
echo $OUTPUT-&amp;gt;continue_button(new moodle_url(&#039;http://domain.com/index.php&#039;, array(&#039;id&#039; =&amp;gt; 2, &#039;userid&#039; =&amp;gt; 4)));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;continuebutton&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;singlebutton&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;form action=&amp;quot;http://domain.com/index.php&amp;quot; method=&amp;quot;get&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;div&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;2&amp;quot; name=&amp;quot;id&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;4&amp;quot; name=&amp;quot;userid&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Continue&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;/form&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== doc_link ====&lt;br /&gt;
Not for general use.&lt;br /&gt;
&lt;br /&gt;
==== error_text ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;error_text(&amp;quot;It&#039;s all broken!&amp;quot;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;error&amp;quot;&amp;gt;It&#039;s all broken!&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== footer ====&lt;br /&gt;
*Simply call $OUTPUT-&amp;gt;footer() at the end of each page. &lt;br /&gt;
*The output may vary depending on which page you are on.&lt;br /&gt;
&lt;br /&gt;
==== form ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$form = new html_form();&lt;br /&gt;
$form-&amp;gt;url = new moodle_url(&#039;http://domain.com/index.php&#039;, array(&#039;id&#039; =&amp;gt; 3, &#039;userid&#039; =&amp;gt; 5));&lt;br /&gt;
$checkbox = html_select_option::make_checkbox(1, false, &#039;Agree to terms&#039;);&lt;br /&gt;
$contents = $OUTPUT-&amp;gt;container(&#039;Terms and conditions: Be kind and courteous&#039;);&lt;br /&gt;
$contents .= $OUTPUT-&amp;gt;checkbox($checkbox, &#039;agree&#039;);&lt;br /&gt;
echo $OUTPUT-&amp;gt;form($form, $contents);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;http://domain.com/index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;79D3tSzYfz&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;3&amp;quot; name=&amp;quot;id&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;5&amp;quot; name=&amp;quot;userid&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;div&amp;gt;Terms and conditions: Be kind and courteous&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;span class=&amp;quot;checkbox agree&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input id=&amp;quot;html_select_option-3a3de0&amp;quot; type=&amp;quot;checkbox&amp;quot; name=&amp;quot;agree&amp;quot; value=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;label for=&amp;quot;html_select_option-3a3de0&amp;quot;&amp;gt;Agree to terms&amp;lt;/label&amp;gt;&lt;br /&gt;
    &amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Submit&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== header ====&lt;br /&gt;
==== heading ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;heading(get_string(&#039;help&#039;), 3, &#039;helptitle&#039;, &#039;uniqueid&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;h3 id=&amp;quot;uniqueid&amp;quot; class=&amp;quot;helptitle&amp;quot;&amp;gt;Help&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== heading_with_help ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$helpicon = new moodle_help_icon();&lt;br /&gt;
$helpicon-&amp;gt;page = &#039;posts&#039;;&lt;br /&gt;
$helpicon-&amp;gt;text = &#039;Help about forum posts&#039;;&lt;br /&gt;
$helpicon-&amp;gt;module = &#039;forum&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;heading_with_help($helpicon);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;heading-with-help&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h2 class=&amp;quot;main help&amp;quot;&amp;gt;Help about forum posts&amp;lt;/h2&amp;gt;&lt;br /&gt;
  &amp;lt;span class=&amp;quot;helplink&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;a id=&amp;quot;html_link-7b0b0d&amp;quot; href=&amp;quot;http://enterprise/cvs_moodle_head/help.php?module=forum&amp;amp;amp;file=posts.html&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;img class=&amp;quot;iconhelp image&amp;quot; src=&amp;quot;http://enterprise/cvs_moodle_head/pix/help.gif&amp;quot; alt=&amp;quot;&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/a&amp;gt;&lt;br /&gt;
  &amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== help_icon ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$helpicon = new moodle_help_icon();&lt;br /&gt;
$helpicon-&amp;gt;page = &#039;posts&#039;;&lt;br /&gt;
$helpicon-&amp;gt;text = &#039;Help about forum posts&#039;;&lt;br /&gt;
$helpicon-&amp;gt;module = &#039;forum&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;help_icon($helpicon);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;helplink&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;a id=&amp;quot;html_link-42560f&amp;quot; href=&amp;quot;http://enterprise/cvs_moodle_head/help.php?module=forum&amp;amp;amp;file=posts.html&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;img class=&amp;quot;iconhelp image&amp;quot; src=&amp;quot;http://enterprise/cvs_moodle_head/pix/help.gif&amp;quot; alt=&amp;quot;Help about forum posts&amp;quot; title=&amp;quot;Help about forum posts&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== htmllist ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$data = array(&#039;Group 1&#039; =&amp;gt; array(&#039;Group 1.1&#039; =&amp;gt; array(&#039;Item 1.1.1&#039;, &#039;Item 1.1.2&#039;), &#039;Item 1.2&#039;),&lt;br /&gt;
              &#039;Group 2&#039; =&amp;gt; array(&#039;Item 2.1&#039;, &#039;Item 2.2&#039;, &#039;Item 2.3&#039;));&lt;br /&gt;
$list = new html_list();&lt;br /&gt;
$list-&amp;gt;type = &#039;ordered&#039;;&lt;br /&gt;
$list-&amp;gt;load_data($data);&lt;br /&gt;
echo $OUTPUT-&amp;gt;htmllist($list);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;ol class=&amp;quot;list-0&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Group 1&lt;br /&gt;
    &amp;lt;ol class=&amp;quot;list-1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;li&amp;gt;Group 1.1&lt;br /&gt;
        &amp;lt;ol class=&amp;quot;list-2&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;li class=&amp;quot;list-item-2-1&amp;quot;&amp;gt;Item 1.1.1&amp;lt;/li&amp;gt;&lt;br /&gt;
          &amp;lt;li class=&amp;quot;list-item-2-2&amp;quot;&amp;gt;Item 1.1.2&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/ol&amp;gt;&lt;br /&gt;
      &amp;lt;/li&amp;gt;&lt;br /&gt;
      &amp;lt;li class=&amp;quot;list-item-1-2&amp;quot;&amp;gt;Item 1.2&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/ol&amp;gt;&lt;br /&gt;
  &amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Group 2&lt;br /&gt;
    &amp;lt;ol class=&amp;quot;list-1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;li class=&amp;quot;list-item-1-1&amp;quot;&amp;gt;Item 2.1&amp;lt;/li&amp;gt;&lt;br /&gt;
      &amp;lt;li class=&amp;quot;list-item-1-2&amp;quot;&amp;gt;Item 2.2&amp;lt;/li&amp;gt;&lt;br /&gt;
      &amp;lt;li class=&amp;quot;list-item-1-3&amp;quot;&amp;gt;Item 2.3&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/ol&amp;gt;&lt;br /&gt;
  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Notes: &lt;br /&gt;
*The class names are generated automatically. For ol and ul classes, the digit represents the depth of nesting. &lt;br /&gt;
*This is also the meaning of the first digit in the list item classes, the second being the number of the list item in the item&#039;s list.&lt;br /&gt;
*Once you have called $list-&amp;gt;load_data($array), the list-&amp;gt;items array is filled with html_list and html_list_item components, which you can setup in more details in preparation for output.&lt;br /&gt;
&lt;br /&gt;
==== image ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$image = new html_image();&lt;br /&gt;
$image-&amp;gt;src = &#039;http://domain.com/help.gif&#039;;&lt;br /&gt;
$image-&amp;gt;alt = &#039;Helpful icon&#039;;&lt;br /&gt;
$image-&amp;gt;width = 24;&lt;br /&gt;
$image-&amp;gt;height = 24;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;img class=&amp;quot;image&amp;quot; style=&amp;quot;height: 24px; width: 24px;&amp;quot; alt=&amp;quot;Helpful icon&amp;quot; src=&amp;quot;http://domain.com/help.gif&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== label ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$label = new html_label();&lt;br /&gt;
$label-&amp;gt;text = &#039;Form element&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;label($label);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;label&amp;gt;Form element&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a rather low-level function, you will rarely need to call it directly. Instead, use labels on subclasses of labelled_html_component:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$field = new html_field();&lt;br /&gt;
$field-&amp;gt;name = &#039;variable1&#039;;&lt;br /&gt;
$field-&amp;gt;id = &#039;myfield&#039;;&lt;br /&gt;
$field-&amp;gt;set_label(&#039;Form element&#039;);&lt;br /&gt;
echo $OUTPUT-&amp;gt;textfield($field);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;textfield variable1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label for=&amp;quot;myfield&amp;quot;&amp;gt;Form element&amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input id=&amp;quot;myfield&amp;quot; type=&amp;quot;text&amp;quot; style=&amp;quot;width: 4em;&amp;quot; name=&amp;quot;variable1&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== link ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$link = new html_link();&lt;br /&gt;
$link-&amp;gt;url = new moodle_url(&#039;http://domain.com/index.php&#039;, array(&#039;id&#039; =&amp;gt; 2, &#039;action&#039; =&amp;gt; &#039;browse&#039;)); // required, but you can use a string instead&lt;br /&gt;
$link-&amp;gt;text = &#039;Browse page 2&#039;; // Required&lt;br /&gt;
echo $OUTPUT-&amp;gt;link($link)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;http://domain.com/index.php?id=2&amp;amp;amp;action=browse&amp;quot;&amp;gt;Browse page 2&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== link_to_popup ====&lt;br /&gt;
*Same API as for link(), but you set a popup_action on the component, and link() will forward it to the link_to_popup() method. You shouldn&#039;t need to call this method directly.&lt;br /&gt;
==== link ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$link = html_link::make(new moodle_url(&#039;http://domain.com/index.php&#039;, array(&#039;id&#039; =&amp;gt; 2, &#039;action&#039; =&amp;gt; &#039;browse&#039;)), &#039;Browse page 2&#039;);&lt;br /&gt;
$link-&amp;gt;add_action(new popup_action(&#039;click&#039;, $link-&amp;gt;url));&lt;br /&gt;
echo $OUTPUT-&amp;gt;link($link)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;a id=&amp;quot;html_link-985165&amp;quot; href=&amp;quot;http://domain.com/index.php?id=2&amp;amp;amp;action=browse&amp;quot;&amp;gt;Browse page 2&amp;lt;/a&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
//&amp;lt;![CDATA[ &lt;br /&gt;
YAHOO.util.Event.addListener(&#039;html_link-985165&#039;, &#039;click&#039;, openpopup, {&amp;quot;url&amp;quot;:&amp;quot;http:\/\/domain.com\/index.php?id=2&amp;amp;action=browse&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;popup&amp;quot;,&amp;quot;options&amp;quot;:&amp;quot;[...]&amp;quot;});&lt;br /&gt;
//]]&amp;gt; &lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== notification ====&lt;br /&gt;
*By default this function works just like container(), with a default class set to &#039;notifyproblem&#039;.&lt;br /&gt;
*It actually inserts a template token which is interpreted and rendered at a later stage.&lt;br /&gt;
&lt;br /&gt;
==== paging_bar ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$pagingbar = moodle_paging_bar::make(120, 3, 20, &#039;http://domain.com/index.php&#039;);&lt;br /&gt;
// Optionally : $pagingbar-&amp;gt;pagevar = &#039;mypage&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;paging_bar($pagingbar);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
  Page: (&lt;br /&gt;
  &amp;lt;a class=&amp;quot;previous&amp;quot; href=&amp;quot;http://domain.com/index.php?page=2&amp;quot;&amp;gt;Previous&amp;lt;/a&amp;gt;&lt;br /&gt;
  )   &lt;br /&gt;
  &amp;lt;a href=&amp;quot;http://domain.com/index.php?page=0&amp;quot;&amp;gt;1&amp;lt;/a&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;quot;http://domain.com/index.php?page=1&amp;quot;&amp;gt;2&amp;lt;/a&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;quot;http://domain.com/index.php?page=2&amp;quot;&amp;gt;3&amp;lt;/a&amp;gt;&lt;br /&gt;
    4  &lt;br /&gt;
  &amp;lt;a href=&amp;quot;http://domain.com/index.php?page=4&amp;quot;&amp;gt;5&amp;lt;/a&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;quot;http://domain.com/index.php?page=5&amp;quot;&amp;gt;6&amp;lt;/a&amp;gt;&lt;br /&gt;
    (&lt;br /&gt;
  &amp;lt;a class=&amp;quot;next&amp;quot; href=&amp;quot;http://domain.com/index.php?page=4&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;
  )&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== radio ====&lt;br /&gt;
==== select ====&lt;br /&gt;
*This method depends heavily on how the passed component is configured, so see [[Output_API#html_select]] For a detailed description&lt;br /&gt;
&lt;br /&gt;
==== select_option ====&lt;br /&gt;
*Used internally by select(), you shouldn&#039;t need to call this directly.&lt;br /&gt;
&lt;br /&gt;
==== spacer ====&lt;br /&gt;
==== table ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$table = new html_table();&lt;br /&gt;
$table-&amp;gt;head = array(&#039;Student&#039;, &#039;Grade&#039;, &#039;Comments&#039;);&lt;br /&gt;
$table-&amp;gt;data = array(&lt;br /&gt;
    array(&#039;Harry Potter&#039;, &#039;76%&#039;, &#039;Getting better&#039;),&lt;br /&gt;
    array(&#039;Rincewind&#039;, &#039;89%&#039;, &#039;Lucky as usual&#039;),&lt;br /&gt;
    array(&#039;Elminster Aumar&#039;, &#039;100%&#039;, &#039;Easy when you know everything!&#039;)&lt;br /&gt;
);&lt;br /&gt;
echo html_writer::table($table);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;table class=&amp;quot;generaltable&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;thead&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;th class=&amp;quot;header c0&amp;quot; scope=&amp;quot;col&amp;quot; style=&amp;quot;white-space: nowrap;&amp;quot;&amp;gt;Student&amp;lt;/th&amp;gt;&lt;br /&gt;
      &amp;lt;th class=&amp;quot;header c1&amp;quot; scope=&amp;quot;col&amp;quot; style=&amp;quot;white-space: nowrap;&amp;quot;&amp;gt;Grade&amp;lt;/th&amp;gt;&lt;br /&gt;
      &amp;lt;th class=&amp;quot;header c2 lastcol&amp;quot; scope=&amp;quot;col&amp;quot; style=&amp;quot;white-space: nowrap;&amp;quot;&amp;gt;Comments&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
  &amp;lt;/thead&amp;gt;&lt;br /&gt;
  &amp;lt;tbody&amp;gt;&lt;br /&gt;
    &amp;lt;tr class=&amp;quot;r0&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Harry Potter&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;76%&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Getting better&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr class=&amp;quot;r1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Rincewind&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;89%&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Lucky as usual&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr class=&amp;quot;r0 lastrow&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Elminster Aumar&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;100%&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Easy when you know everything!&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
  &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== textfield ====&lt;br /&gt;
==== user_picture ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$user = new stdClass();&lt;br /&gt;
$user-&amp;gt;id = 1;&lt;br /&gt;
$userpic = new moodle_user_picture();&lt;br /&gt;
$userpic-&amp;gt;user = $user;&lt;br /&gt;
$userpic-&amp;gt;courseid = 1;&lt;br /&gt;
&lt;br /&gt;
echo $OUTPUT-&amp;gt;user_picture($userpic);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;img class=&amp;quot;image&amp;quot; style=&amp;quot;height: 35px; width: 35px;&amp;quot; alt=&amp;quot;Picture of Admin User&amp;quot; src=&amp;quot;http://enterprise/cvs_moodle_head/pix/u/f2.png&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cli_core_renderer ===&lt;br /&gt;
&lt;br /&gt;
== Actions ==&lt;br /&gt;
*Component actions are objects that represent Moodle&#039;s response to a user&#039;s action on a component.&lt;br /&gt;
*These objects bind to a moodle_html_component or one of its subclasses.&lt;br /&gt;
*The renderers are responsible for interpreting these actions and generating the appropriate Javascript code.&lt;br /&gt;
&lt;br /&gt;
=== component_action ===&lt;br /&gt;
*This is the base class for all component actions. It includes the name of the event (click, change, keydown etc.), the name of the Javascript function to be called, and an optional array of arguments to pass to the JS function.&lt;br /&gt;
*&#039;&#039;&#039;Important!&#039;&#039;&#039;: the JS function called by this event handler will always receive two arguments: &amp;quot;event&amp;quot; and &amp;quot;args&amp;quot;. &lt;br /&gt;
**The first is a DOM event object and can be used within the function to get the element on which the action was performed, and get information about the event (such as which key was pressed). &lt;br /&gt;
**The second argument (args) is an object with named parameters (a &amp;quot;hash&amp;quot;) that includes the optional JS arguments you defined in the component_action instantiation.&lt;br /&gt;
*Any component which receives an action (through the moodle_html_component::add_action($action) method) needs to be given a unique DOM id attribute. If you do not specify it, one will be automatically generated for you.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$link = new html_link();&lt;br /&gt;
$link-&amp;gt;url = new moodle_url(&#039;/index.php&#039;, array(&#039;id&#039; =&amp;gt; 2, &#039;delete&#039; =&amp;gt; 5));&lt;br /&gt;
$link-&amp;gt;text = &#039;Delete this website&#039;;&lt;br /&gt;
&lt;br /&gt;
$link-&amp;gt;add_action(&#039;click&#039;, &#039;confirm_dialog&#039;, array(&#039;message&#039; =&amp;gt; &#039;Are you sure?&#039;));&lt;br /&gt;
// OR&lt;br /&gt;
$action = new component_action(&#039;click&#039;, &#039;confirm_dialog&#039;, array(&#039;message&#039; =&amp;gt; &#039;Are you REALLY sure?&#039;));&lt;br /&gt;
$link-&amp;gt;add_action($action);&lt;br /&gt;
&lt;br /&gt;
echo $OUTPUT-&amp;gt;link($link);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
*Actions cannot yet be stacked in a component. This means that the above code will behave erratically because we are setting two actions for the same event. It is better to write a custom, more complex JS function than to try to bind several event handlers to the same component.&lt;br /&gt;
&lt;br /&gt;
=== popup_action ===&lt;br /&gt;
*This action opens up a new window using the given $url value.&lt;br /&gt;
*It has a $params associative array with the arguments to the JS window.open() function. It has sensible defaults, but you can override them if necessary.&lt;br /&gt;
&lt;br /&gt;
== Factories ==&lt;br /&gt;
&lt;br /&gt;
== Theme Config ==&lt;br /&gt;
&lt;br /&gt;
== XHTML Container Stack ==&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous functions ==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[How_Moodle_outputs_HTML]]&lt;br /&gt;
* [[Migrating your code to the 2.0 rendering_API]]&lt;br /&gt;
* [[Outputting HTML in 2.0]]&lt;br /&gt;
* [[Theme_changes]]&lt;/div&gt;</summary>
		<author><name>Simontite</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Output_API&amp;diff=34570</id>
		<title>Output API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Output_API&amp;diff=34570"/>
		<updated>2012-07-26T08:34:11Z</updated>

		<summary type="html">&lt;p&gt;Simontite: /* moodle_user_picture */ Fix link to user_picture example usage and output&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{obsolete}}&lt;br /&gt;
See [[Migrating_your_code_to_the_2.0_rendering_API#Outputting_HTML_specific_to_your_module|this page]] for more up-to-date information. --[[User:David Mudrak|David Mudrak]] 22:16, 23 August 2009 (UTC)&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Components ==&lt;br /&gt;
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:&lt;br /&gt;
* Components do not have defined constructors with arguments. Passing arguments to the default constructor will not do anything useful.&lt;br /&gt;
* Some components have a constructor which is used exclusively to instantiate object member variables.&lt;br /&gt;
* 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.&lt;br /&gt;
* The prepare() method always behaves the same way, regardless of which renderer is used. This ensures consistency of the component&#039;s variables.&lt;br /&gt;
* Additional &amp;quot;shortcut&amp;quot; methods are sometimes added to provide a more high-level API to developers.&lt;br /&gt;
&lt;br /&gt;
=== moodle_html_component ===&lt;br /&gt;
*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.&lt;br /&gt;
*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&#039; PHP docs for details on variables and functions.&lt;br /&gt;
*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.&lt;br /&gt;
*A set_label($text, $for=null) is defined, with the first argument accepting either a string or a html_label component, in which latter case the second argument is ignored. If the component does not have an $id value, one will be generated and assigned to the label&#039;s $for value unless a html_label object is given as the $text argument. For this reason, if you explicitly set a component&#039;s $id value, make sure set_label() is called after you set that value.&lt;br /&gt;
&lt;br /&gt;
=== HTML low-level components ===&lt;br /&gt;
This list of components replicate basic HTML elements. They are prefixed with html_ to make it clear that they are the basic building blocks of the output API.&lt;br /&gt;
&lt;br /&gt;
==== html_label ====&lt;br /&gt;
*Many HTML elements may have a label (input fields, dropdowns etc.). Some rendering functions look for this label and render it accordingly.&lt;br /&gt;
*html_label requires a $text value, and should be given a $for value for accessibility reasons. It is rendered ultimately by $OUTPUT-&amp;gt;label(html_label $label).&lt;br /&gt;
&lt;br /&gt;
==== html_field ====&lt;br /&gt;
*Represents a HTML input field. Can be used to output any input type, although some of its variables only apply to some types (e.g. maxlength only applies to text inputs).&lt;br /&gt;
*It has a shortcut method for preparing a text input: make_text($name, $value, $alt, $maxlength).&lt;br /&gt;
&lt;br /&gt;
==== html_button ====&lt;br /&gt;
*Represents a HTML button, which may be rendered in many different ways, though by default it is rendered as an input field of type &amp;quot;button&amp;quot;.&lt;br /&gt;
*Requires a $text value (by default used as the HTML &amp;quot;value&amp;quot; attribute)&lt;br /&gt;
&lt;br /&gt;
==== html_link ====&lt;br /&gt;
*Represents a link, by default rendered by the $OUTPUT-&amp;gt;link() function as HTML: &lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;$url&amp;quot;&amp;gt;$text&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== html_image ====&lt;br /&gt;
*Simple class representing an image, rendered by $OUTPUT-&amp;gt;image().&lt;br /&gt;
*The $alt variable is set to HTML_ATTR_EMPTY by default. This constant is interpreted by the renderer as an attribute with an empty string as a value. If you use an actual empty string, the attribute will not be output at all, which would break XHTML strict for the &amp;lt;img/&amp;gt; tag.&lt;br /&gt;
&lt;br /&gt;
==== html_form ====&lt;br /&gt;
*This component represents a form &#039;wrapper&#039; with an optional html_button object. You can use $OUTPUT-&amp;gt;form($form, $contents) to output a form with any HTML you want within it.&lt;br /&gt;
*The object requires a $url value, which can either be a string or a moodle_url object. In the prepare() method, this variable will be converted to a moodle_url.&lt;br /&gt;
*If the $method &amp;quot;post&amp;quot; is used, the sesskey param will be added automatically&lt;br /&gt;
*You can use the $params array to specify hidden inputs, but it will be ignored if you give a moodle_url as the $url value (because moodle_urls include query params).&lt;br /&gt;
*This object is also used by the $OUTPUT-&amp;gt;button($formwithbutton) and the $OUTPUT-&amp;gt;confirm($message, $formcontinue, $formcancel) methods.&lt;br /&gt;
&lt;br /&gt;
==== html_list ====&lt;br /&gt;
*Represents a HTML nested list.&lt;br /&gt;
*Has a load_data($tree, $level=0) recursive method which take a nested array and stores instantiated html_list_item objects in the $items array.&lt;br /&gt;
*CSS classes are automatically added to each element in the list, to allow for custom styling.&lt;br /&gt;
*This is rendered by $OUTPUT-&amp;gt;htmllist($list) as a &amp;lt;nowiki&amp;gt;&amp;lt;ul&amp;gt; or &amp;lt;ol&amp;gt;&amp;lt;/nowiki&amp;gt; element, but could be used to output nav menus etc. by yet unwritten output methods.&lt;br /&gt;
*Use the $type variable to specify if the list should be ordered or unordered.&lt;br /&gt;
&lt;br /&gt;
==== html_list_item ====&lt;br /&gt;
*Represents a list item used by the html_list component. Only has a $value variable, but also benefits from all other variables and methods of the moodle_html_component base class.&lt;br /&gt;
&lt;br /&gt;
==== html_table ====&lt;br /&gt;
*Represents a HTML table with data&lt;br /&gt;
*Is intended to replace the old flexible_table class&lt;br /&gt;
*The $data array either holds an associate array of arrays representing rows and cells, or it can be set up with html_table_row and html_table_cell objects, for finer control over the look and layout of the table cells.&lt;br /&gt;
*In the html_writer::table($table) method, the $data array&#039;s contents are converted into html_table_row and html_table_cell objects if they are not already of that type.&lt;br /&gt;
&lt;br /&gt;
==== html_table_row ====&lt;br /&gt;
*A simple component holding an array of html_table_cell objects.&lt;br /&gt;
&lt;br /&gt;
==== html_table_cell ====&lt;br /&gt;
*This represents a table cell, and is aggregated by a html_table_row object, itself aggregated by html_table.&lt;br /&gt;
*This component&#039;s variables mirror those of the XHTML &amp;lt;nowiki&amp;gt;&amp;lt;td&amp;gt; or &amp;lt;th&amp;gt;&amp;lt;/nowiki&amp;gt; elements (differentiated by the $header boolean)&lt;br /&gt;
&lt;br /&gt;
==== html_select ====&lt;br /&gt;
*This object is by far the most complex HTML component in Moodle. It represents any element that presents the user with a choice. This includes:&lt;br /&gt;
*#A dropdown menu (&amp;lt;nowiki&amp;gt;&amp;lt;select&amp;gt; tag&amp;lt;/nowiki&amp;gt;), optionally with automatic redirection upon selection of an option&lt;br /&gt;
*#A set of radio buttons (&amp;lt;nowiki&amp;gt;&amp;lt;input type=&amp;quot;radio&amp;quot; /&amp;gt; tag&amp;lt;/nowiki&amp;gt;)&lt;br /&gt;
*#A set of checkboxes (&amp;lt;nowiki&amp;gt;&amp;lt;input type=&amp;quot;checkbox&amp;quot; /&amp;gt; tag&amp;lt;/nowiki&amp;gt;)&lt;br /&gt;
*However, remember that the HTML tags given above are the default rendering of a html_select object. This object can hold so much data that it could be rendered in a multiple of different ways, not necessarily using these traditional HTML tags.&lt;br /&gt;
*This class has a special method initialise_options() which converts the given $options into html_select_optgroup and html_select_option objects. This allows you to override these options&#039; defaults and add style, classes and component_action objects before the object is sent to the renderer.&lt;br /&gt;
&lt;br /&gt;
*Some examples follow:&lt;br /&gt;
&lt;br /&gt;
===== Basic example =====&lt;br /&gt;
The following will output a basic drop-down menu, ready to be included in a form:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$select = html_select::make(array(&#039;1&#039; =&amp;gt; &#039;Value 1&#039;, &#039;2&#039; =&amp;gt; &#039;Value 2&#039;), &#039;choice1&#039;, &#039;2&#039;));&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;select id=&amp;quot;menuchoice1&amp;quot; class=&amp;quot;menuchoice1 select&amp;quot; name=&amp;quot;choice1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;Choose...&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;1&amp;quot;&amp;gt;Value 1&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option selected=&amp;quot;selected&amp;quot; value=&amp;quot;2&amp;quot;&amp;gt;Value 2&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Note that a default &amp;quot;Choose...&amp;quot; option with a value of 0 is added to the menu. To remove this, follow the next example:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$select-&amp;gt;nothinglabel = false;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This will remove the default option completely.&lt;br /&gt;
&lt;br /&gt;
===== Nested menus =====&lt;br /&gt;
You can also render a menu with one level of nesting, rendered as a dropdown with optgroups. You just need to do two things to achieve that:&lt;br /&gt;
#Specify $select-&amp;gt;nested = true&lt;br /&gt;
#Either:&lt;br /&gt;
#*$select-&amp;gt;load_data($flatarray), which requires a rather cryptic syntax with double-dashes for optgroups&lt;br /&gt;
#*$select-&amp;gt;load_data($nestedarray), the first level&#039;s keys are the names of the optgroups, their arrays are the options&#039; value=&amp;gt;label pairs.&lt;br /&gt;
#*Prepare the data directly as html_select_optgroup and html_select_option objects. This method requires more code but less debugging because it is a lot less brittle than a string-based syntax, and it allows more customised classes, JS actions etc. on each individual option.&lt;br /&gt;
&lt;br /&gt;
The preferred method is the second one in the majority of cases, because it is easy to setup and debug. The first method should be avoided and will not be demonstrated here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Method 2:&lt;br /&gt;
$options = array(&#039;Group1&#039; =&amp;gt; array(&#039;value1&#039; =&amp;gt; &#039;Option 1&#039;, &#039;value2&#039; =&amp;gt; &#039;Option 2&#039;), &#039;Group2&#039; =&amp;gt; array(&#039;value3&#039; =&amp;gt; &#039;Option 3&#039;, &#039;value4&#039; =&amp;gt; &#039;Option 4&#039;));&lt;br /&gt;
$select = html_select::make($options, &#039;choice1&#039;, &#039;value1&#039;);&lt;br /&gt;
$select-&amp;gt;nested = true;&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&lt;br /&gt;
// Method 3:&lt;br /&gt;
$optgroup1 = new html_select_optgroup();&lt;br /&gt;
$optgroup2 = new html_select_optgroup();&lt;br /&gt;
$optgroup1-&amp;gt;text = &#039;Group1&#039;;&lt;br /&gt;
$optgroup2-&amp;gt;text = &#039;Group2&#039;;&lt;br /&gt;
&lt;br /&gt;
$option1 = new html_select_option();&lt;br /&gt;
$option2 = new html_select_option();&lt;br /&gt;
$option3 = new html_select_option();&lt;br /&gt;
$option4 = new html_select_option();&lt;br /&gt;
&lt;br /&gt;
$option1-&amp;gt;text = &#039;Option 1&#039;;&lt;br /&gt;
$option1-&amp;gt;value = &#039;value1&#039;;&lt;br /&gt;
$option2-&amp;gt;text = &#039;Option 2&#039;;&lt;br /&gt;
$option2-&amp;gt;value = &#039;value2&#039;;&lt;br /&gt;
$option3-&amp;gt;text = &#039;Option 3&#039;;&lt;br /&gt;
$option3-&amp;gt;value = &#039;value3&#039;;&lt;br /&gt;
$option4-&amp;gt;text = &#039;Option 4&#039;;&lt;br /&gt;
$option4-&amp;gt;value = &#039;value4&#039;;&lt;br /&gt;
&lt;br /&gt;
$optgroup1-&amp;gt;options = array($option1, $option2);&lt;br /&gt;
$optgroup2-&amp;gt;options = array($option3, $option4);&lt;br /&gt;
&lt;br /&gt;
$select = html_select::make(array($optgroup1, $optgroup2), &#039;choice1&#039;, &#039;value1&#039;);&lt;br /&gt;
$select-&amp;gt;nested = true;&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Both these methods Output:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;select id=&amp;quot;menuchoice1&amp;quot; class=&amp;quot;menuchoice1 select&amp;quot; name=&amp;quot;choice1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;optgroup label=&amp;quot;Group1&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;option selected=&amp;quot;selected&amp;quot; value=&amp;quot;value1&amp;quot;&amp;gt;Option 1&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;option value=&amp;quot;value2&amp;quot;&amp;gt;Option 2&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;/optgroup&amp;gt;&lt;br /&gt;
  &amp;lt;optgroup label=&amp;quot;Group2&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;option value=&amp;quot;value3&amp;quot;&amp;gt;Option 3&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;option value=&amp;quot;value4&amp;quot;&amp;gt;Option 4&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;/optgroup&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Although the last method looks very code-intensive, most of it would obviously be reduced using foreach loops, and it allows for much more customisation of the components.&lt;br /&gt;
&lt;br /&gt;
===== Yes/No menu =====&lt;br /&gt;
A common use case is to print a Yes/No menu. This could be output as two radio buttons, but it is sometimes output as a menu. The two cases are demonstrated here:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$select = html_select::make_yes_no(&#039;choice1&#039;, 1);&lt;br /&gt;
$select-&amp;gt;nothinglabel = false; // Don&#039;t forget to do this, or the &amp;quot;Choose...&amp;quot; option will appear and have the same value as the &amp;quot;No&amp;quot; option!&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;select id=&amp;quot;menuchoice1&amp;quot; class=&amp;quot;menuchoice1 select&amp;quot; name=&amp;quot;choice1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;No&amp;lt;/option&amp;gt;&lt;br /&gt;
  &amp;lt;option selected=&amp;quot;selected&amp;quot; value=&amp;quot;1&amp;quot;&amp;gt;Yes&amp;lt;/option&amp;gt;&lt;br /&gt;
&amp;lt;/select&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Radio buttons:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$select-&amp;gt;rendertype = &#039;radio&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;span class=&amp;quot;radiogroup choice1 rb0&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label for=&amp;quot;html_select_option-b4d4bd&amp;quot;&amp;gt;No&amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input id=&amp;quot;html_select_option-b4d4bd&amp;quot; type=&amp;quot;radio&amp;quot; name=&amp;quot;choice1&amp;quot; value=&amp;quot;0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;radiogroup choice1 rb1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label for=&amp;quot;html_select_option-1eaa39&amp;quot;&amp;gt;Yes&amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input id=&amp;quot;html_select_option-1eaa39&amp;quot; type=&amp;quot;radio&amp;quot; checked=&amp;quot;checked&amp;quot; name=&amp;quot;choice1&amp;quot; value=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, in many cases it is better to display a yes/no choice as a single checkbox. For this purpose, it is better to instantiate a single html_option object and pass it to $OUTPUT-&amp;gt;checkbox().&lt;br /&gt;
&lt;br /&gt;
===== Date/Time selectors =====&lt;br /&gt;
NOTE: This part of the API is under review&lt;br /&gt;
&lt;br /&gt;
The html_select object can be used to output date or time selectors. A shortcut method is provided for this purpose: make_time_selector($type, $currenttime, $step);&lt;br /&gt;
For more concise code, you can use the higher-level method make_time_selectors($selectors, $currentime, $step);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$dayselector = html_select::make_time_selector(&#039;days&#039;, &#039;myday&#039;, &#039;120308000&#039;);&lt;br /&gt;
$monthselector = html_select::make_time_selector(&#039;months&#039;, &#039;mymonth&#039;, &#039;120308000&#039;);&lt;br /&gt;
$yearselector = html_select::make_time_selector(&#039;years&#039;, &#039;myyear&#039;, &#039;120308000&#039;);&lt;br /&gt;
$hourselector = html_select::make_time_selector(&#039;hours&#039;, &#039;myhour&#039;, &#039;120308000&#039;);&lt;br /&gt;
$minuteselector = html_select::make_time_selector(&#039;minutes&#039;, &#039;myminute&#039;, &#039;120308000&#039;, 5);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($dayselector);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($monthselector);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($yearselector);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($hourselector);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($minuteselector);&lt;br /&gt;
&lt;br /&gt;
// OR&lt;br /&gt;
$selectors = html_select::make_time_selectors(array(&#039;days&#039; =&amp;gt; &#039;myday&#039;, &#039;months&#039; =&amp;gt; &#039;mymonth&#039;, &#039;years&#039; =&amp;gt; &#039;myyear&#039;, &#039;hours&#039; =&amp;gt; &#039;myhour&#039;, &#039;minutes&#039; =&amp;gt; &#039;myminute&#039;), &#039;120308000&#039;, 5);&lt;br /&gt;
foreach ($selectors as $select) {&lt;br /&gt;
    echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
[[Image:timeselectors.png]]&lt;br /&gt;
&lt;br /&gt;
===== Popup Forms =====&lt;br /&gt;
*This is a really bad name for a dropdown menu that redirects the user when an option is selected.&lt;br /&gt;
*html_select::make_popup_form() is a shortcut method for returning an object ready for rendering through $OUTPUT-&amp;gt;select()&lt;br /&gt;
*The basic premise of a &amp;quot;popup form&amp;quot; is that each option has as its value the URL to which the user should be redirected when that option is selected&lt;br /&gt;
*To simplify this process, make_popup_form() takes a URL as its first argument, and the name of a query param as the second. It is expected that the option values represent the value that will be assigned to this &amp;quot;variable&amp;quot; parameter.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$options = array(1 =&amp;gt; &#039;Page 1&#039;, 2 =&amp;gt; &#039;Page 2&#039;, 3 =&amp;gt; &#039;Page 3&#039;);&lt;br /&gt;
$select = html_select::make_popup_form(&#039;http://domain.com/index.php&#039;, &#039;id&#039;, $options, &#039;myform&#039;);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;form id=&amp;quot;myform&amp;quot; class=&amp;quot;popupform&amp;quot; action=&amp;quot;http://enterprise/cvs_moodle_head/course/jumpto.php&amp;quot; method=&amp;quot;get&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;JEgniUhzzx&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;select id=&amp;quot;myform_jump&amp;quot; class=&amp;quot;menujump select&amp;quot; name=&amp;quot;jump&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;Choose...&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/index.php?id=1&amp;quot;&amp;gt;Page 1&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/index.php?id=2&amp;quot;&amp;gt;Page 2&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/index.php?id=3&amp;quot;&amp;gt;Page 3&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
    &amp;lt;div id=&amp;quot;noscriptmyform&amp;quot; style=&amp;quot;display: none;&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Go&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sometimes you will need some of the URLs to have a different base, or to have more parameters that change between options. The best way to achieve this is demonstrated here:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$options = array(&#039;http://domain.com/index.php?id=1&#039; =&amp;gt; &#039;Page 1&#039;, &lt;br /&gt;
                 &#039;http://domain.com/otherpage/index.php?modid=1&#039; =&amp;gt; &#039;Page 2&#039;, &lt;br /&gt;
                 &#039;http://domain.com/index.php?id=1&amp;amp;othervar=2&#039; =&amp;gt; &#039;Page 3&#039;);&lt;br /&gt;
$select = html_select::make_popup_form(&#039;&#039;, &#039;&#039;, $options, &#039;myform&#039;);&lt;br /&gt;
$select-&amp;gt;override_option_values($options);&lt;br /&gt;
echo $OUTPUT-&amp;gt;select($select);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;form id=&amp;quot;myform&amp;quot; class=&amp;quot;popupform&amp;quot; action=&amp;quot;http://enterprise/cvs_moodle_head/course/jumpto.php&amp;quot; method=&amp;quot;get&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;JEgniUhzzx&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;select id=&amp;quot;myform_jump&amp;quot; class=&amp;quot;menujump select&amp;quot; name=&amp;quot;jump&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;0&amp;quot;&amp;gt;Choose...&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/index.php?id=1&amp;quot;&amp;gt;Page 1&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/otherpage/index.php?modid=1&amp;quot;&amp;gt;Page 2&amp;lt;/option&amp;gt;&lt;br /&gt;
      &amp;lt;option value=&amp;quot;http://domain.com/index.php?id=1&amp;amp;othervar=2&amp;quot;&amp;gt;Page 3&amp;lt;/option&amp;gt;&lt;br /&gt;
    &amp;lt;/select&amp;gt;&lt;br /&gt;
    &amp;lt;div id=&amp;quot;noscriptmyform&amp;quot; style=&amp;quot;display: none;&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Go&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== html_select_option ====&lt;br /&gt;
*This component represents an option&lt;br /&gt;
*It is not necessarily rendered as an &amp;lt;nowiki&amp;gt;&amp;lt;option&amp;gt;&amp;lt;/nowiki&amp;gt; tag, but can also be rendered as a radio or a checkbox&lt;br /&gt;
*It can be aggregated by html_select and html_select_optgroup, or used by itself in $OUTPUT-&amp;gt;checkbox($option, $name)&lt;br /&gt;
*It has a shortcut method for preparing a checkbox for output: make_checkbox($value, $selected, $label, $alt);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$checkbox = html_select_option::make_checkbox(&#039;1&#039;, false, get_string(&#039;donotask&#039;));&lt;br /&gt;
echo $OUTPUT-&amp;gt;checkbox($checkbox, &#039;donotask&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;checkbox donotask&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input id=&amp;quot;html_select_option-e7be90&amp;quot; type=&amp;quot;checkbox&amp;quot; name=&amp;quot;donotask&amp;quot; value=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;label for=&amp;quot;html_select_option-e7be90&amp;quot;&amp;gt;Do Not Ask&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
*Note that an ID is generated in this case even though no component_action was added. This is the default behaviour for the checkbox() method.&lt;br /&gt;
&lt;br /&gt;
==== html_select_optgroup ====&lt;br /&gt;
*This represents an option group, used only by html_select to group options together. It doesn&#039;t do anything particularly useful in itself apart from aggregating html_select_option objects and having a text value.&lt;br /&gt;
*It benefits from all the moodle_html_component variables and methods.&lt;br /&gt;
&lt;br /&gt;
=== Moodle components ===&lt;br /&gt;
The following components do not map exactly to HTML elements, so they are prefixed with moodle_.&lt;br /&gt;
&lt;br /&gt;
==== moodle_paging_bar ====&lt;br /&gt;
*Represents a paging bar used to navigate a large list of records like users, forum posts etc.&lt;br /&gt;
*Since 4 parameters are required, a shortcut function is provided: moodle_paging_bar::make($totalcount, $page, $perpage, $baseurl)&lt;br /&gt;
*The first page has a value of 0 but is displayed as 1, so remember this offset.&lt;br /&gt;
*If you have multiple paging bars on one page for different lists, set the $pagevar variable&lt;br /&gt;
*See [[Output_API#paging_bar]] for example usage and output&lt;br /&gt;
&lt;br /&gt;
==== moodle_user_picture ====&lt;br /&gt;
*Represents a user&#039;s picture to be output through $OUTPUT-&amp;gt;user_picture()&lt;br /&gt;
*Requires at least a $user object of stdClass with a minimum of data (id) and a $courseid&lt;br /&gt;
*If no specific image is given (as a html_image object), then the default image is loaded&lt;br /&gt;
*See [[Output_API#user_picture]] for example usage and output&lt;br /&gt;
&lt;br /&gt;
==== moodle_action_icon ====&lt;br /&gt;
*Simply put, this is a linked image.&lt;br /&gt;
*See [[Output_API:action_icon]] for example usage and output&lt;br /&gt;
&lt;br /&gt;
==== moodle_help_icon ====&lt;br /&gt;
See [[Output_API#help_icon]] For example usage. Replaces the old helpbutton() global function.&lt;br /&gt;
&lt;br /&gt;
== Renderers ==&lt;br /&gt;
=== renderer_base ===&lt;br /&gt;
* Simple base class for Moodle renderers.&lt;br /&gt;
* Tracks the xhtml_container_stack to use, which is passed in in the constructor.&lt;br /&gt;
* Also has methods to facilitate generating HTML output.&lt;br /&gt;
&lt;br /&gt;
==== output_tag methods ====&lt;br /&gt;
* Low-level functions for outputting specific HTML tags. &lt;br /&gt;
* For empty tags (with no content), use output_empty_tag&lt;br /&gt;
&lt;br /&gt;
==== pix_url ====&lt;br /&gt;
* Same as old_icon_url, but for old module icons&lt;br /&gt;
* The equivalent for &amp;quot;$CFG-&amp;gt;modpixpath/$mod/icon.gif&amp;quot; is mod_icon_url(&#039;icon&#039;, $mod)&lt;br /&gt;
&lt;br /&gt;
==== prepare_event_handlers(&amp;amp;$component) ====&lt;br /&gt;
* Used by rendering functions to prepare JS event listeners for components that may require it. &lt;br /&gt;
* All components that can receive user input should go through this method&lt;br /&gt;
&lt;br /&gt;
==== prepare_legacy_width_and_height($component) ====&lt;br /&gt;
* Returns the correct CSS for components that have the deprecated $height and/or $width attributes&lt;br /&gt;
&lt;br /&gt;
=== core_renderer ===&lt;br /&gt;
Since these functions are very well documented inline (phpdoc), I will only put examples here, without in-depth explanations.&lt;br /&gt;
&lt;br /&gt;
==== action_icon ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$icon = new moodle_action_icon();&lt;br /&gt;
$icon-&amp;gt;image-&amp;gt;src = $OUTPUT-&amp;gt;old_icon_url(&#039;moodlelogo&#039;);&lt;br /&gt;
$icon-&amp;gt;image-&amp;gt;alt = &#039;What is moodle?&#039;;&lt;br /&gt;
$icon-&amp;gt;link-&amp;gt;url = new moodle_url(&#039;http://domain.com/index.php&#039;);&lt;br /&gt;
$icon-&amp;gt;add_confirm_action(&#039;Are you sure?&#039;); // Optional. Equivalent to doing $icon-&amp;gt;link-&amp;gt;add_confirm_action(&#039;Are you sure?&#039;);&lt;br /&gt;
echo $OUTPUT-&amp;gt;action_icon($icon);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;a id=&amp;quot;html_link-2b4310&amp;quot; href=&amp;quot;http://domain.com/index.php&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;img class=&amp;quot;action-icon image&amp;quot; alt=&amp;quot;What is moodle?&amp;quot; src=&amp;quot;http://enterprise/cvs_moodle_head/pix/moodlelogo.gif&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/a&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
//&amp;lt;![CDATA[ &lt;br /&gt;
YAHOO.util.Event.addListener(&#039;html_link-2b4310&#039;, &#039;click&#039;, confirm_dialog, {&amp;quot;message&amp;quot;:&amp;quot;Are you sure?&amp;quot;});&lt;br /&gt;
//]]&amp;gt; &lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== box, box_start and box_end ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;box(&#039;A message of some kind&#039;);&lt;br /&gt;
// OR&lt;br /&gt;
echo $OUTPUT-&amp;gt;box_start();&lt;br /&gt;
echo &#039;A message of some kind&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;box_end();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;box generalbox&amp;quot;&amp;gt;A message of some kind&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== button ====&lt;br /&gt;
*Be aware that this method&#039;s signature requires a html_form component as its only argument. This form object must have a $button value (html_button)&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$form = new html_form();&lt;br /&gt;
$form-&amp;gt;url = new moodle_url(&#039;http://domain.com/index.php&#039;, array(&#039;id&#039; =&amp;gt; 3, &#039;userid&#039; =&amp;gt; 5));&lt;br /&gt;
$form-&amp;gt;button-&amp;gt;text = &#039;My account&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;button($form);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;singlebutton&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;form action=&amp;quot;http://domain.com/index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;div&amp;gt;&lt;br /&gt;
      &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;fXlccUgFTz&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;3&amp;quot; name=&amp;quot;id&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;5&amp;quot; name=&amp;quot;userid&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;My account&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== checkbox ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$checkbox = html_select_option::make_checkbox(&#039;1&#039;, false, get_string(&#039;donotask&#039;));&lt;br /&gt;
echo $OUTPUT-&amp;gt;checkbox($checkbox, &#039;donotask&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;checkbox donotask&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;input id=&amp;quot;html_select_option-e7be90&amp;quot; type=&amp;quot;checkbox&amp;quot; name=&amp;quot;donotask&amp;quot; value=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;label for=&amp;quot;html_select_option-e7be90&amp;quot;&amp;gt;Do Not Ask&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== close_window_button ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;close_window_button();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;closewindow&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;singlebutton&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;form action=&amp;quot;http://enterprise/cvs_moodle_head/#&amp;quot; method=&amp;quot;get&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;div&amp;gt;&lt;br /&gt;
        &amp;lt;input id=&amp;quot;html_button-d35ffa&amp;quot; class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Close this window&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;/form&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
//&amp;lt;![CDATA[ &lt;br /&gt;
YAHOO.util.Event.addListener(&#039;html_button-d35ffa&#039;, &#039;click&#039;, close_window);&lt;br /&gt;
//]]&amp;gt; &lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== confirm ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;confirm(&#039;Are you sure?&#039;, &#039;/index.php?delete=1&#039;, &#039;/index.php&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;notice&amp;quot; class=&amp;quot;box generalbox&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;Are you sure?&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;buttons&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;singlebutton&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;form action=&amp;quot;http://enterprise/cvs_moodle_head/index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;fXlccUgFTz&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;1&amp;quot; name=&amp;quot;delete&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Yes&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
      &amp;lt;/form&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;singlebutton&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;form action=&amp;quot;http://enterprise/cvs_moodle_head/index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;fXlccUgFTz&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
          &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;No&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
      &amp;lt;/form&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== container, container_start and container_end ====&lt;br /&gt;
*Container differs from box in two ways:&lt;br /&gt;
*#It doesn&#039;t add default CSS classes (box adds a &amp;quot;box&amp;quot; class and a &amp;quot;generalbox&amp;quot; class unless the default is overridden)&lt;br /&gt;
*#It is stored in the XHTML stack as a &amp;quot;container&amp;quot;, not a &amp;quot;box&amp;quot;&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;container(&#039;A message of some kind&#039;, &#039;important&#039;, &#039;notice&#039;);&lt;br /&gt;
// OR&lt;br /&gt;
echo $OUTPUT-&amp;gt;container_start(&#039;important&#039;, &#039;notice&#039;);&lt;br /&gt;
echo &#039;A message of some kind&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;container_end();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;notice&amp;quot; class=&amp;quot;important&amp;quot;&amp;gt;A message of some kind&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== continue_button ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;continue_button(&#039;http://domain.com/index.php?id=2&amp;amp;userid=4&#039;);&lt;br /&gt;
// OR (preferred)&lt;br /&gt;
echo $OUTPUT-&amp;gt;continue_button(new moodle_url(&#039;http://domain.com/index.php&#039;, array(&#039;id&#039; =&amp;gt; 2, &#039;userid&#039; =&amp;gt; 4)));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;continuebutton&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;singlebutton&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;form action=&amp;quot;http://domain.com/index.php&amp;quot; method=&amp;quot;get&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;div&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;2&amp;quot; name=&amp;quot;id&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;4&amp;quot; name=&amp;quot;userid&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Continue&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;/form&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== doc_link ====&lt;br /&gt;
Not for general use.&lt;br /&gt;
&lt;br /&gt;
==== error_text ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;error_text(&amp;quot;It&#039;s all broken!&amp;quot;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;error&amp;quot;&amp;gt;It&#039;s all broken!&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== footer ====&lt;br /&gt;
*Simply call $OUTPUT-&amp;gt;footer() at the end of each page. &lt;br /&gt;
*The output may vary depending on which page you are on.&lt;br /&gt;
&lt;br /&gt;
==== form ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$form = new html_form();&lt;br /&gt;
$form-&amp;gt;url = new moodle_url(&#039;http://domain.com/index.php&#039;, array(&#039;id&#039; =&amp;gt; 3, &#039;userid&#039; =&amp;gt; 5));&lt;br /&gt;
$checkbox = html_select_option::make_checkbox(1, false, &#039;Agree to terms&#039;);&lt;br /&gt;
$contents = $OUTPUT-&amp;gt;container(&#039;Terms and conditions: Be kind and courteous&#039;);&lt;br /&gt;
$contents .= $OUTPUT-&amp;gt;checkbox($checkbox, &#039;agree&#039;);&lt;br /&gt;
echo $OUTPUT-&amp;gt;form($form, $contents);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;http://domain.com/index.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;79D3tSzYfz&amp;quot; name=&amp;quot;sesskey&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;3&amp;quot; name=&amp;quot;id&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; value=&amp;quot;5&amp;quot; name=&amp;quot;userid&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;div&amp;gt;Terms and conditions: Be kind and courteous&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;span class=&amp;quot;checkbox agree&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;input id=&amp;quot;html_select_option-3a3de0&amp;quot; type=&amp;quot;checkbox&amp;quot; name=&amp;quot;agree&amp;quot; value=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;label for=&amp;quot;html_select_option-3a3de0&amp;quot;&amp;gt;Agree to terms&amp;lt;/label&amp;gt;&lt;br /&gt;
    &amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;input class=&amp;quot;singlebutton&amp;quot; type=&amp;quot;submit&amp;quot; value=&amp;quot;Submit&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== header ====&lt;br /&gt;
==== heading ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
echo $OUTPUT-&amp;gt;heading(get_string(&#039;help&#039;), 3, &#039;helptitle&#039;, &#039;uniqueid&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;h3 id=&amp;quot;uniqueid&amp;quot; class=&amp;quot;helptitle&amp;quot;&amp;gt;Help&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== heading_with_help ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$helpicon = new moodle_help_icon();&lt;br /&gt;
$helpicon-&amp;gt;page = &#039;posts&#039;;&lt;br /&gt;
$helpicon-&amp;gt;text = &#039;Help about forum posts&#039;;&lt;br /&gt;
$helpicon-&amp;gt;module = &#039;forum&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;heading_with_help($helpicon);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;heading-with-help&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;h2 class=&amp;quot;main help&amp;quot;&amp;gt;Help about forum posts&amp;lt;/h2&amp;gt;&lt;br /&gt;
  &amp;lt;span class=&amp;quot;helplink&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;a id=&amp;quot;html_link-7b0b0d&amp;quot; href=&amp;quot;http://enterprise/cvs_moodle_head/help.php?module=forum&amp;amp;amp;file=posts.html&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;img class=&amp;quot;iconhelp image&amp;quot; src=&amp;quot;http://enterprise/cvs_moodle_head/pix/help.gif&amp;quot; alt=&amp;quot;&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/a&amp;gt;&lt;br /&gt;
  &amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== help_icon ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$helpicon = new moodle_help_icon();&lt;br /&gt;
$helpicon-&amp;gt;page = &#039;posts&#039;;&lt;br /&gt;
$helpicon-&amp;gt;text = &#039;Help about forum posts&#039;;&lt;br /&gt;
$helpicon-&amp;gt;module = &#039;forum&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;help_icon($helpicon);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;helplink&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;a id=&amp;quot;html_link-42560f&amp;quot; href=&amp;quot;http://enterprise/cvs_moodle_head/help.php?module=forum&amp;amp;amp;file=posts.html&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;img class=&amp;quot;iconhelp image&amp;quot; src=&amp;quot;http://enterprise/cvs_moodle_head/pix/help.gif&amp;quot; alt=&amp;quot;Help about forum posts&amp;quot; title=&amp;quot;Help about forum posts&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== htmllist ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$data = array(&#039;Group 1&#039; =&amp;gt; array(&#039;Group 1.1&#039; =&amp;gt; array(&#039;Item 1.1.1&#039;, &#039;Item 1.1.2&#039;), &#039;Item 1.2&#039;),&lt;br /&gt;
              &#039;Group 2&#039; =&amp;gt; array(&#039;Item 2.1&#039;, &#039;Item 2.2&#039;, &#039;Item 2.3&#039;));&lt;br /&gt;
$list = new html_list();&lt;br /&gt;
$list-&amp;gt;type = &#039;ordered&#039;;&lt;br /&gt;
$list-&amp;gt;load_data($data);&lt;br /&gt;
echo $OUTPUT-&amp;gt;htmllist($list);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;ol class=&amp;quot;list-0&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Group 1&lt;br /&gt;
    &amp;lt;ol class=&amp;quot;list-1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;li&amp;gt;Group 1.1&lt;br /&gt;
        &amp;lt;ol class=&amp;quot;list-2&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;li class=&amp;quot;list-item-2-1&amp;quot;&amp;gt;Item 1.1.1&amp;lt;/li&amp;gt;&lt;br /&gt;
          &amp;lt;li class=&amp;quot;list-item-2-2&amp;quot;&amp;gt;Item 1.1.2&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/ol&amp;gt;&lt;br /&gt;
      &amp;lt;/li&amp;gt;&lt;br /&gt;
      &amp;lt;li class=&amp;quot;list-item-1-2&amp;quot;&amp;gt;Item 1.2&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/ol&amp;gt;&lt;br /&gt;
  &amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Group 2&lt;br /&gt;
    &amp;lt;ol class=&amp;quot;list-1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;li class=&amp;quot;list-item-1-1&amp;quot;&amp;gt;Item 2.1&amp;lt;/li&amp;gt;&lt;br /&gt;
      &amp;lt;li class=&amp;quot;list-item-1-2&amp;quot;&amp;gt;Item 2.2&amp;lt;/li&amp;gt;&lt;br /&gt;
      &amp;lt;li class=&amp;quot;list-item-1-3&amp;quot;&amp;gt;Item 2.3&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/ol&amp;gt;&lt;br /&gt;
  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Notes: &lt;br /&gt;
*The class names are generated automatically. For ol and ul classes, the digit represents the depth of nesting. &lt;br /&gt;
*This is also the meaning of the first digit in the list item classes, the second being the number of the list item in the item&#039;s list.&lt;br /&gt;
*Once you have called $list-&amp;gt;load_data($array), the list-&amp;gt;items array is filled with html_list and html_list_item components, which you can setup in more details in preparation for output.&lt;br /&gt;
&lt;br /&gt;
==== image ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$image = new html_image();&lt;br /&gt;
$image-&amp;gt;src = &#039;http://domain.com/help.gif&#039;;&lt;br /&gt;
$image-&amp;gt;alt = &#039;Helpful icon&#039;;&lt;br /&gt;
$image-&amp;gt;width = 24;&lt;br /&gt;
$image-&amp;gt;height = 24;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;img class=&amp;quot;image&amp;quot; style=&amp;quot;height: 24px; width: 24px;&amp;quot; alt=&amp;quot;Helpful icon&amp;quot; src=&amp;quot;http://domain.com/help.gif&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== label ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$label = new html_label();&lt;br /&gt;
$label-&amp;gt;text = &#039;Form element&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;label($label);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;label&amp;gt;Form element&amp;lt;/label&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a rather low-level function, you will rarely need to call it directly. Instead, use labels on subclasses of labelled_html_component:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$field = new html_field();&lt;br /&gt;
$field-&amp;gt;name = &#039;variable1&#039;;&lt;br /&gt;
$field-&amp;gt;id = &#039;myfield&#039;;&lt;br /&gt;
$field-&amp;gt;set_label(&#039;Form element&#039;);&lt;br /&gt;
echo $OUTPUT-&amp;gt;textfield($field);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;textfield variable1&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;label for=&amp;quot;myfield&amp;quot;&amp;gt;Form element&amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;input id=&amp;quot;myfield&amp;quot; type=&amp;quot;text&amp;quot; style=&amp;quot;width: 4em;&amp;quot; name=&amp;quot;variable1&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== link ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$link = new html_link();&lt;br /&gt;
$link-&amp;gt;url = new moodle_url(&#039;http://domain.com/index.php&#039;, array(&#039;id&#039; =&amp;gt; 2, &#039;action&#039; =&amp;gt; &#039;browse&#039;)); // required, but you can use a string instead&lt;br /&gt;
$link-&amp;gt;text = &#039;Browse page 2&#039;; // Required&lt;br /&gt;
echo $OUTPUT-&amp;gt;link($link)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;http://domain.com/index.php?id=2&amp;amp;amp;action=browse&amp;quot;&amp;gt;Browse page 2&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== link_to_popup ====&lt;br /&gt;
*Same API as for link(), but you set a popup_action on the component, and link() will forward it to the link_to_popup() method. You shouldn&#039;t need to call this method directly.&lt;br /&gt;
==== link ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$link = html_link::make(new moodle_url(&#039;http://domain.com/index.php&#039;, array(&#039;id&#039; =&amp;gt; 2, &#039;action&#039; =&amp;gt; &#039;browse&#039;)), &#039;Browse page 2&#039;);&lt;br /&gt;
$link-&amp;gt;add_action(new popup_action(&#039;click&#039;, $link-&amp;gt;url));&lt;br /&gt;
echo $OUTPUT-&amp;gt;link($link)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;a id=&amp;quot;html_link-985165&amp;quot; href=&amp;quot;http://domain.com/index.php?id=2&amp;amp;amp;action=browse&amp;quot;&amp;gt;Browse page 2&amp;lt;/a&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
//&amp;lt;![CDATA[ &lt;br /&gt;
YAHOO.util.Event.addListener(&#039;html_link-985165&#039;, &#039;click&#039;, openpopup, {&amp;quot;url&amp;quot;:&amp;quot;http:\/\/domain.com\/index.php?id=2&amp;amp;action=browse&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;popup&amp;quot;,&amp;quot;options&amp;quot;:&amp;quot;[...]&amp;quot;});&lt;br /&gt;
//]]&amp;gt; &lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== notification ====&lt;br /&gt;
*By default this function works just like container(), with a default class set to &#039;notifyproblem&#039;.&lt;br /&gt;
*It actually inserts a template token which is interpreted and rendered at a later stage.&lt;br /&gt;
&lt;br /&gt;
==== paging_bar ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$pagingbar = moodle_paging_bar::make(120, 3, 20, &#039;http://domain.com/index.php&#039;);&lt;br /&gt;
// Optionally : $pagingbar-&amp;gt;pagevar = &#039;mypage&#039;;&lt;br /&gt;
echo $OUTPUT-&amp;gt;paging_bar($pagingbar);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
  Page: (&lt;br /&gt;
  &amp;lt;a class=&amp;quot;previous&amp;quot; href=&amp;quot;http://domain.com/index.php?page=2&amp;quot;&amp;gt;Previous&amp;lt;/a&amp;gt;&lt;br /&gt;
  )   &lt;br /&gt;
  &amp;lt;a href=&amp;quot;http://domain.com/index.php?page=0&amp;quot;&amp;gt;1&amp;lt;/a&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;quot;http://domain.com/index.php?page=1&amp;quot;&amp;gt;2&amp;lt;/a&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;quot;http://domain.com/index.php?page=2&amp;quot;&amp;gt;3&amp;lt;/a&amp;gt;&lt;br /&gt;
    4  &lt;br /&gt;
  &amp;lt;a href=&amp;quot;http://domain.com/index.php?page=4&amp;quot;&amp;gt;5&amp;lt;/a&amp;gt;&lt;br /&gt;
  &amp;lt;a href=&amp;quot;http://domain.com/index.php?page=5&amp;quot;&amp;gt;6&amp;lt;/a&amp;gt;&lt;br /&gt;
    (&lt;br /&gt;
  &amp;lt;a class=&amp;quot;next&amp;quot; href=&amp;quot;http://domain.com/index.php?page=4&amp;quot;&amp;gt;Next&amp;lt;/a&amp;gt;&lt;br /&gt;
  )&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== radio ====&lt;br /&gt;
==== select ====&lt;br /&gt;
*This method depends heavily on how the passed component is configured, so see [[Output_API#html_select]] For a detailed description&lt;br /&gt;
&lt;br /&gt;
==== select_option ====&lt;br /&gt;
*Used internally by select(), you shouldn&#039;t need to call this directly.&lt;br /&gt;
&lt;br /&gt;
==== spacer ====&lt;br /&gt;
==== table ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$table = new html_table();&lt;br /&gt;
$table-&amp;gt;head = array(&#039;Student&#039;, &#039;Grade&#039;, &#039;Comments&#039;);&lt;br /&gt;
$table-&amp;gt;data = array(&lt;br /&gt;
    array(&#039;Harry Potter&#039;, &#039;76%&#039;, &#039;Getting better&#039;),&lt;br /&gt;
    array(&#039;Rincewind&#039;, &#039;89%&#039;, &#039;Lucky as usual&#039;),&lt;br /&gt;
    array(&#039;Elminster Aumar&#039;, &#039;100%&#039;, &#039;Easy when you know everything!&#039;)&lt;br /&gt;
);&lt;br /&gt;
echo html_writer::table($table);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;table class=&amp;quot;generaltable&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;thead&amp;gt;&lt;br /&gt;
    &amp;lt;tr&amp;gt;&lt;br /&gt;
      &amp;lt;th class=&amp;quot;header c0&amp;quot; scope=&amp;quot;col&amp;quot; style=&amp;quot;white-space: nowrap;&amp;quot;&amp;gt;Student&amp;lt;/th&amp;gt;&lt;br /&gt;
      &amp;lt;th class=&amp;quot;header c1&amp;quot; scope=&amp;quot;col&amp;quot; style=&amp;quot;white-space: nowrap;&amp;quot;&amp;gt;Grade&amp;lt;/th&amp;gt;&lt;br /&gt;
      &amp;lt;th class=&amp;quot;header c2 lastcol&amp;quot; scope=&amp;quot;col&amp;quot; style=&amp;quot;white-space: nowrap;&amp;quot;&amp;gt;Comments&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
  &amp;lt;/thead&amp;gt;&lt;br /&gt;
  &amp;lt;tbody&amp;gt;&lt;br /&gt;
    &amp;lt;tr class=&amp;quot;r0&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Harry Potter&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;76%&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Getting better&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr class=&amp;quot;r1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Rincewind&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;89%&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Lucky as usual&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
    &amp;lt;tr class=&amp;quot;r0 lastrow&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Elminster Aumar&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;100%&amp;lt;/td&amp;gt;&lt;br /&gt;
      &amp;lt;td class=&amp;quot;cell&amp;quot;&amp;gt;Easy when you know everything!&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;/tr&amp;gt;&lt;br /&gt;
  &amp;lt;/tbody&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== textfield ====&lt;br /&gt;
==== user_picture ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$user = new stdClass();&lt;br /&gt;
$user-&amp;gt;id = 1;&lt;br /&gt;
$userpic = new moodle_user_picture();&lt;br /&gt;
$userpic-&amp;gt;user = $user;&lt;br /&gt;
$userpic-&amp;gt;courseid = 1;&lt;br /&gt;
&lt;br /&gt;
echo $OUTPUT-&amp;gt;user_picture($userpic);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
Outputs:&lt;br /&gt;
&amp;lt;code html4strict&amp;gt;&lt;br /&gt;
&amp;lt;img class=&amp;quot;image&amp;quot; style=&amp;quot;height: 35px; width: 35px;&amp;quot; alt=&amp;quot;Picture of Admin User&amp;quot; src=&amp;quot;http://enterprise/cvs_moodle_head/pix/u/f2.png&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cli_core_renderer ===&lt;br /&gt;
&lt;br /&gt;
== Actions ==&lt;br /&gt;
*Component actions are objects that represent Moodle&#039;s response to a user&#039;s action on a component.&lt;br /&gt;
*These objects bind to a moodle_html_component or one of its subclasses.&lt;br /&gt;
*The renderers are responsible for interpreting these actions and generating the appropriate Javascript code.&lt;br /&gt;
&lt;br /&gt;
=== component_action ===&lt;br /&gt;
*This is the base class for all component actions. It includes the name of the event (click, change, keydown etc.), the name of the Javascript function to be called, and an optional array of arguments to pass to the JS function.&lt;br /&gt;
*&#039;&#039;&#039;Important!&#039;&#039;&#039;: the JS function called by this event handler will always receive two arguments: &amp;quot;event&amp;quot; and &amp;quot;args&amp;quot;. &lt;br /&gt;
**The first is a DOM event object and can be used within the function to get the element on which the action was performed, and get information about the event (such as which key was pressed). &lt;br /&gt;
**The second argument (args) is an object with named parameters (a &amp;quot;hash&amp;quot;) that includes the optional JS arguments you defined in the component_action instantiation.&lt;br /&gt;
*Any component which receives an action (through the moodle_html_component::add_action($action) method) needs to be given a unique DOM id attribute. If you do not specify it, one will be automatically generated for you.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$link = new html_link();&lt;br /&gt;
$link-&amp;gt;url = new moodle_url(&#039;/index.php&#039;, array(&#039;id&#039; =&amp;gt; 2, &#039;delete&#039; =&amp;gt; 5));&lt;br /&gt;
$link-&amp;gt;text = &#039;Delete this website&#039;;&lt;br /&gt;
&lt;br /&gt;
$link-&amp;gt;add_action(&#039;click&#039;, &#039;confirm_dialog&#039;, array(&#039;message&#039; =&amp;gt; &#039;Are you sure?&#039;));&lt;br /&gt;
// OR&lt;br /&gt;
$action = new component_action(&#039;click&#039;, &#039;confirm_dialog&#039;, array(&#039;message&#039; =&amp;gt; &#039;Are you REALLY sure?&#039;));&lt;br /&gt;
$link-&amp;gt;add_action($action);&lt;br /&gt;
&lt;br /&gt;
echo $OUTPUT-&amp;gt;link($link);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
*Actions cannot yet be stacked in a component. This means that the above code will behave erratically because we are setting two actions for the same event. It is better to write a custom, more complex JS function than to try to bind several event handlers to the same component.&lt;br /&gt;
&lt;br /&gt;
=== popup_action ===&lt;br /&gt;
*This action opens up a new window using the given $url value.&lt;br /&gt;
*It has a $params associative array with the arguments to the JS window.open() function. It has sensible defaults, but you can override them if necessary.&lt;br /&gt;
&lt;br /&gt;
== Factories ==&lt;br /&gt;
&lt;br /&gt;
== Theme Config ==&lt;br /&gt;
&lt;br /&gt;
== XHTML Container Stack ==&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous functions ==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[How_Moodle_outputs_HTML]]&lt;br /&gt;
* [[Migrating your code to the 2.0 rendering_API]]&lt;br /&gt;
* [[Outputting HTML in 2.0]]&lt;br /&gt;
* [[Theme_changes]]&lt;/div&gt;</summary>
		<author><name>Simontite</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Page_API&amp;diff=34387</id>
		<title>Page API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Page_API&amp;diff=34387"/>
		<updated>2012-07-06T10:09:51Z</updated>

		<summary type="html">&lt;p&gt;Simontite: /* Context */ equivilant -&amp;gt; equivalent&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Page API is used to set up the current page, add JavaScript, and configure how things will be displayed to the user.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The Page API is an integral part of any Moodle page. It also the developer to set things up they way they envisage it. Through the Page API you can set things like the title, initial heading, where the user is for the navigation, and which layout you think the page should use.&lt;br /&gt;
&lt;br /&gt;
This document starts off with a simple example, and then proceeds to provide a more complete description of how to set up a page for display.&lt;br /&gt;
&lt;br /&gt;
==A simple example==&lt;br /&gt;
This example covers how to set up a basic page for use within an activity plugin and is undoubtedly the simplest example as much of the work is done behind the scenes for you.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// File: /mod/mymodulename/view.php&lt;br /&gt;
require_once(&#039;../../config.php&#039;);&lt;br /&gt;
$cmid = required_param(&#039;id&#039;, PARAM_INT);&lt;br /&gt;
$cm = get_coursemodule_from_id(&#039;mymodulename&#039;, $cmid, 0, false, MUST_EXIST);&lt;br /&gt;
$course = $DB-&amp;gt;get_record(&#039;course&#039;, array(&#039;id&#039; =&amp;gt; $cm-&amp;gt;course), &#039;*&#039;, MUST_EXIST);&lt;br /&gt;
&lt;br /&gt;
require_login($course, true, $cm);&lt;br /&gt;
$PAGE-&amp;gt;set_url(&#039;/mod/mymodulename/view.php&#039;, array(&#039;id&#039; =&amp;gt; $cm-&amp;gt;id));&lt;br /&gt;
$PAGE-&amp;gt;set_title(&#039;My modules page title&#039;);&lt;br /&gt;
$PAGE-&amp;gt;set_heading(&#039;My modules page heading&#039;);&lt;br /&gt;
&lt;br /&gt;
// The rest of your code goes below this.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
I&#039;m going to assume you know what the first four lines are doing, if not you are starting in the wrong place.&lt;br /&gt;
&lt;br /&gt;
So lets start at require_login and assume you already have the course and course module objects ready to use. When you call require_login part of the magic it does for you is set up the basic for the current page.&amp;lt;br /&amp;gt;&lt;br /&gt;
In the case of the example above because require_login is given a course and course module it is already setting up much of the page for you. It is giving the course and course module objects to the page, setting the context for the page to the course modules context, and setting the page layout to &#039;&#039;incourse&#039;&#039; so that you get the standard look of a course module.&lt;br /&gt;
&lt;br /&gt;
The set up that we are having to do is as follows:&lt;br /&gt;
# Set the URL for the page. This MUST be done.&lt;br /&gt;
# Set a title for the page. Most likely will be shown in the &amp;lt;title&amp;gt; tag.&lt;br /&gt;
# Set the heading for the page. Most likely used in the pages header.&lt;br /&gt;
&lt;br /&gt;
It&#039;s important to mention that this has to be done before output starts. That means you must set up the page before the header is printed and before you instantiate any moodleform instances.&lt;br /&gt;
&lt;br /&gt;
And that is it, if you were to add a bit of simple output there you would get a page that already looks like other module pages you would have seen. Simple as.&lt;br /&gt;
&lt;br /&gt;
==$PAGE The Moodle page global==&lt;br /&gt;
For every page request Moodle sets up a couple of global structures that you will likely need. $DB the database object, and $CFG which stores configuration are two that you are likely already aware of. $PAGE is the focus of this article, it is a moodle_page instance that stores all of the information and is used by the output library $OUTPUT when displaying the page.&amp;lt;br /&amp;gt;&lt;br /&gt;
It&#039;s important to note the difference between $PAGE and $OUTPUT, $PAGE is for setting up the page and $OUTPUT is for displaying the page. $PAGE contains lots of logic and magic, $OUTPUT is purely about display and does little more than produce HTML.&lt;br /&gt;
&lt;br /&gt;
==Setting up the page==&lt;br /&gt;
When creating a page in Moodle there are a couple of things that you must set, and a couple of things that get set for you in many cases but not all of the time.&lt;br /&gt;
&lt;br /&gt;
===URL===&lt;br /&gt;
This is an absolute must, failing to set this will lead Moodle to display an error that it has not been set.&amp;lt;br /&amp;gt;&lt;br /&gt;
It can be set in the following manner:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$PAGE-&amp;gt;set_url(new moodle_url(&#039;/page/to/your/file.php&#039;, array(&#039;key&#039; =&amp;gt; &#039;value&#039;, &#039;id&#039; =&amp;gt; 3)));&lt;br /&gt;
$PAGE-&amp;gt;set_url(&#039;/page/to/your/file.php&#039;, array(&#039;key&#039; =&amp;gt; &#039;value&#039;, &#039;id&#039; =&amp;gt; 3));&lt;br /&gt;
$PAGE-&amp;gt;set_url(&#039;/page/to/your/file.php?key=value&amp;amp;id=3&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code sets the page URL 3 times, and highlights the 3 different ways you can set the URL. Either of the first two methods are the preferred way as it provides 100% accuracy when processing the URL. Internally set_url() converts what ever you give it to a moodle_url object.&lt;br /&gt;
&lt;br /&gt;
The URL that you give to the page is going to be use by a lot of Moodle core API&#039;s. Most importantly it is going to be used to create the navigation for your page so it&#039;s very important you set it accurately.&lt;br /&gt;
&lt;br /&gt;
===Context===&lt;br /&gt;
This is an absolute must as well, however in many cases it will be set for you magically by Moodle.&lt;br /&gt;
&lt;br /&gt;
In order to set the context for the page you must provide a context object, in Moodle 2.2 and greater this will look as follows:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Moodle 2.2 and greater&lt;br /&gt;
$PAGE-&amp;gt;set_context(context_system::instance());&lt;br /&gt;
$PAGE-&amp;gt;set_context(context_coursecat::instance($categoryid));&lt;br /&gt;
$PAGE-&amp;gt;set_context(context_course::instance($courseid));&lt;br /&gt;
$PAGE-&amp;gt;set_context(context_module::instance($moduleid));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.0+, and Moodle 2.1+ the following is the equivalent code:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// Moodle 2.2 and greater&lt;br /&gt;
$PAGE-&amp;gt;set_context(get_system_context());&lt;br /&gt;
$PAGE-&amp;gt;set_context(get_context_instance(CONTEXT_COURSECAT, $categoryid));&lt;br /&gt;
$PAGE-&amp;gt;set_context(get_context_instance(CONTEXT_COURSE, $courseid));&lt;br /&gt;
$PAGE-&amp;gt;set_context(get_context_instance(CONTEXT_MODULE, $moduleid));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In both examples above setting different types of contexts has been illustrated however you should only ever call set_context() once with the context that is most appropriate to the page you are creating.&amp;lt;br /&amp;gt;&lt;br /&gt;
If it is a plugin then the context to use would be the context you are using for your capability checks.&lt;br /&gt;
&lt;br /&gt;
As mentioned above the other thing to be aware of is that in some circumstances this gets automatically set for you.&amp;lt;br /&amp;gt;&lt;br /&gt;
If your script calls require_login (and most scripts have to) and you are providing a course, or a module to your require login call then you will not need to call set_context().&amp;lt;br /&amp;gt;&lt;br /&gt;
This is because require_login handles it for you.&lt;br /&gt;
&lt;br /&gt;
If your script doesn&#039;t call require_login, or you don&#039;t call it with a course and/or module then you will need to manually set the context as shown.&lt;br /&gt;
&lt;br /&gt;
===Optional set up===&lt;br /&gt;
The following are optional extras you can set up against the PAGE object that you are likely to encounter throughout Moodle core, and are likely to want to use yourself.&lt;br /&gt;
====Page layout====&lt;br /&gt;
The following code sets the pages layout to the standard layout, the most generic layout in the arsenal.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$PAGE-&amp;gt;set_pagelayout(&#039;standard&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
When setting the page layout you should use the layout that is the closest match to the page you are creating. Layouts are used by themes to determine what is is shown on the page. The most prominent difference between layouts is the block regions they support. The default layout `&#039;&#039;base&#039;&#039;` for example doesn&#039;t normally have any block regions at all, where as normally `&#039;&#039;standard&#039;&#039;` has the most generic layout and several block regions.&lt;br /&gt;
&lt;br /&gt;
There are dozens of different layouts that can be, and are used throughout Moodle core that you can use within your code. For a full list of common layouts you are best too look at theme/base/config.php or refer to the list below.&lt;br /&gt;
&lt;br /&gt;
Note: It&#039;s important to know that the theme determines what layouts are available and how each looks. If you select a layout that the theme doesn&#039;t support then it will revert to the default layout while using that theme.&amp;lt;br /&amp;gt;Themes are also able to specify additional layouts, however its important to spot them and know that while they may work with one theme they are unlikely to work as you expect with other themes.&lt;br /&gt;
&lt;br /&gt;
====Base theme page layouts====&lt;br /&gt;
The following is a list of the layouts defined by the base theme. Theme designers are encouraged to make the base theme a parent of their custom theme so you can be sure that in 99% of cases these layouts will be available.&lt;br /&gt;
{| class=&amp;quot;nicetable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Layout&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| base&lt;br /&gt;
| Most backwards compatible layout without the blocks. This is the layout used by default.&lt;br /&gt;
|-&lt;br /&gt;
| standard&lt;br /&gt;
| Standard layout with blocks, this is recommended for most pages with general information&lt;br /&gt;
|-&lt;br /&gt;
| course&lt;br /&gt;
| The course main page uses this layout.&lt;br /&gt;
|-&lt;br /&gt;
| coursecategory&lt;br /&gt;
| Category course listings.&lt;br /&gt;
|-&lt;br /&gt;
| incourse&lt;br /&gt;
| Used for areas within a course, typical for modules. Default page layout if $cm specified in require_login().&lt;br /&gt;
|-&lt;br /&gt;
| frontpage&lt;br /&gt;
| The site home page uses this.&lt;br /&gt;
|-&lt;br /&gt;
| admin&lt;br /&gt;
| Admin and settings pages as well as server administration scripts.&lt;br /&gt;
|-&lt;br /&gt;
| mydashboard&lt;br /&gt;
| The users dashboard.&lt;br /&gt;
|-&lt;br /&gt;
| mypublic&lt;br /&gt;
| A users public profile uses this layout.&lt;br /&gt;
|-&lt;br /&gt;
| login&lt;br /&gt;
| The login screen.&lt;br /&gt;
|-&lt;br /&gt;
| popup&lt;br /&gt;
| Pages that appear in popup windows, usually no navigation, blocks, or header.&lt;br /&gt;
|-&lt;br /&gt;
| frametop&lt;br /&gt;
| Used for the outermost content of a page constructed with frames. Usually no blocks and minimal footer.&lt;br /&gt;
|-&lt;br /&gt;
| embedded&lt;br /&gt;
| Embedded pages such as content for iframes/objects. Needs as much space as possible usually no blocks, header, or footer.&lt;br /&gt;
|-&lt;br /&gt;
| maintenance&lt;br /&gt;
| Used during upgrade, installation, and when maintenance mode is enabled.&lt;br /&gt;
|-&lt;br /&gt;
| print&lt;br /&gt;
| Gets used when printing a page. Normally just a simple header and no blocks.&lt;br /&gt;
|-&lt;br /&gt;
| redirect&lt;br /&gt;
| A special layout used during a redirect. Normally with content only.&lt;br /&gt;
|-&lt;br /&gt;
| report&lt;br /&gt;
| Used for reports within Moodle. Special layout designed to handle horizontal scrolling in a nice way.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Title====&lt;br /&gt;
Setting an appropriate title is certainly a must for any properly designed page. While it is optional it is highly recommended that you set the title.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$PAGE-&amp;gt;set_title(&#039;This is my title&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
When setting the title for the page you need to provide just the string you want to use for the title. It should be a basic string and contain no HTML. Any HTML will be stripped out as the title is used within the &amp;lt;title&amp;gt; tag in the HTML head.&lt;br /&gt;
&lt;br /&gt;
====Heading====&lt;br /&gt;
Like title it is highly recommended that you set a meaningful heading for the page, although it is optional.&amp;lt;br /&amp;gt;The heading is normally displayed at the top of the page before the rest of the content starts. However it is up to the layout defined by the theme as to where it is displayed. Not all layouts will display a heading but I encourage you to always set one even if you are using a layout that doesn&#039;t support headings. This way if you are using a theme that uses a heading on every page regardless of layout things still look consistent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$PAGE-&amp;gt;set_heading(get_string(&#039;pluginname&#039;, &#039;local_myplugin&#039;), 3);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When setting a heading there is just one argument, the string to use for the heading. It should be a basic string and contain no HTML.&lt;br /&gt;
&lt;br /&gt;
=== Advanced set up ===&lt;br /&gt;
The following are advanced optional methods you can call to further set up your page. In most cases you will never need to use these.&lt;br /&gt;
&lt;br /&gt;
; set_activity_record : If you have called require_login with a course module, or you have manually set a course module on $PAGE then one other thing you may want to do is set the activity module record on $PAGE as well.&amp;lt;br /&amp;gt;This is best done when you have already fetched the activity record yourself in which case manually setting the activity record may reduce the number of queries for the page by 1.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_activity_record($activityrecord)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_blocks_editing_capability : Using this method you can set an additional capability that users must posses before being able to edit blocks on this page.&amp;lt;br /&amp;gt;By default &#039;moodle/site:manageblocks&#039; is used however there are sometimes reasons to use a different capability.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_blocks_editing_capability($strcapability)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_button : This allows you to set some HTML that will be shown in the navigation bar where the `Turn on editing` button normally lives.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_button($htmlstring)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_cacheable : By setting this to false the page will be sent with headers to prevent the client from caching the page. Defaults to true.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_cacheable(true/false)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_category_by_id : Allows you to set a category that this page is displaying. Calling this will force the $PAGE-&amp;gt;course to be set to the front page course.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_category_by_id($categoryid)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_cm : Like set page above, sometimes you need to manually set the course module for $PAGE. Again you must set the context to the context of the course module if you call this.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_cm($coursemodulerecord)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_course : This allows you to set the course the page belongs to. Normally when you call require_login the course you give it automatically gets sent to $PAGE for you.&amp;lt;br /&amp;gt;However if you don&#039;t want to require login for the course, but you need it in $PAGE then you can call set_course and provide it.&amp;lt;br /&amp;gt;Note that if you do this then you MUST use the context of the course when calling set_context().&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_course($courserecord)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_docs_path : Normally this gets automatically constructed for you, however in some circumstances you may want to manually set it.&amp;lt;br /&amp;gt;This allows you to have several pages that all point to the same docs page rather than requiring a docs page for each.&amp;lt;br /&amp;gt;The docs page link is normally shown by a theme in the footer.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_docs_path($strpath)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_focuscontrol : If you pass this method an element id when the page loads on the client focus will be shifted to the element with the corresponding id.&amp;lt;br /&amp;gt;Using this function is a REALLY bad idea in most situations because changing focus automatically in a browser is a nightmare for the vision impaired and those using screen readers.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_focuscontrol($controlid)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_headingmenu : This allows you to set some HTML that will be shown next to the pages main heading where the language select box normally lives.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_headingmenu($htmlstring)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_other_editing_capability : Can be used to set an additional capability that the user must posses before they can turn editing on for this page.&amp;lt;br /&amp;gt;This is useful if you can an editing more for your page that is more than just editing blocks.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_other_editing_capability($strcapability)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_pagetype : This gets automatically set up for by default to the path of your file e.g. mod/mymod/index.php will set up as mod-mymod-index.&amp;lt;br /&amp;gt;This is absolutely fine in 99% of cases however every now and again there is a reason to override it.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_pagetype($strpagetype)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_periodic_refresh_delay : If set a meta tag gets added to the page header causing it to refresh intermittently.&amp;lt;br /&amp;gt;This is rarely needed but can be useful if you need to automatically refresh the likes of a chat page, or news feed.&amp;lt;br /&amp;gt;Today it is not recommended to use this, but instead to create a means of getting additional content via AJAX.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_periodic_refresh_delay($intdelay)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_popup_notification_allowed : Allow or disallow popup notifications on this page. Things like messaging can cause messages to popup at the bottom of the screen sometimes.&amp;lt;br /&amp;gt;On some pages this functionality is not desired and can be stopped by calling this method and using false as the first argument.&amp;lt;br /&amp;gt;Popups are allowed by default.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_popup_notification_allowed(true/false)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; set_subpage : If context-&amp;gt;id and pagetype are not enough to uniquely identify this page and you need to include another string to make it more unique you can do it by calling this method setting a custom sub page type.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;set_subpage($strsubpage)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; add_body_class : Adds a CSS class to the body tag that will be printed by the Output API as part of the header.&amp;lt;br /&amp;gt;This is useful for adding classes to the body tag that describe the content of the page and may be required for styling the whole page, or for including indicator classes that may be useful to look for in JavaScript.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;add_body_class($strcssclass)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; add_body_classes : Adds an array of CSS classes to the body tag. Have a look at the above comment for &#039;&#039;&#039;add_body_class&#039;&#039;&#039; for more details.&lt;br /&gt;
&amp;lt;code php&amp;gt;$PAGE-&amp;gt;add_body_classes($arrayofclasses)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Getting information about the page==&lt;br /&gt;
As well of setting up the page you can of course get information back from it about the page it has been set up to display.&amp;lt;br /&amp;gt;&lt;br /&gt;
Anything you set against the page can be retrieved as can any information that was set magically for you by other methods.&lt;br /&gt;
&lt;br /&gt;
The following are the most interesting and likely useful things you can get back from the page.&lt;br /&gt;
&lt;br /&gt;
; activityrecord : The activityrecord will be the record from the database that relates to the cm that was set by require_login, or manually by your code.&amp;lt;br /&amp;gt;For example if you provided a $cm instance that related to a forum this will be a row from the forum table.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;activityrecord;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; blockmanager : This is the block manager responsible for loading the all of the blocks that will be shown on the page.&amp;lt;br /&amp;gt;For more information see the [[Blocks API]].&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;blockmanager;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; bodyid : The id that will be given to the body tag when the page is displayed.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;bodyid&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; categories : An array of all the categories the page course belongs to, starting with the immediately containing category.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;categories&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; category : The category that the page course belongs to.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;category&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; cm : The course module that has been set for the page.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;cm&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; course : The course that has been set for the page.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;course&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; devicetypeinuse : The device the user is using browse the page.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;devicetypeinuse&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; headerprinted : Is true if the page header has already been printed. &lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;headerprinted&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; heading : The page heading.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;heading&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; navbar : Gets a reference to the pages navigation bar so that you can interact with that. See the [[Navigation API]] for more information.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;navbar&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; navigation : Gets a reference to the navigation for the page. See the [[Navigation API]] for more information.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; requires : Gets the page requirements manager that handles any JavaScript and special CSS requirements for the page.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;requires&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; settingsnav : Gets the settings navigation for the page. See the [[Navigation API]] for more information.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;settingsnav&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; theme : Gets the theme that is being used for the page. Is a theme_config object.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;theme&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; title : Gets the title for the page.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;title&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; url : Gets the URL that was set for the page. Is a moodle_url object.&lt;br /&gt;
&amp;lt;code php&amp;gt;$var = $PAGE-&amp;gt;url&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==FAQs==&lt;br /&gt;
&lt;br /&gt;
; I don&#039;t have any blocks on my page? : This has happened because you have not set a page layout that uses blocks OR you have set it after output has started. Once output has started you cannot change integral aspects of that page that are used for the initial output. Included is the page title, heading, url and layout.&lt;br /&gt;
&lt;br /&gt;
; I am getting a notice about not having set the page URL but I have set it? : As above you must set up the page before output starts, trying to do so will lead to notices and developer warnings about having things in the wrong order.&lt;br /&gt;
&lt;br /&gt;
; What starts output? : Output starts when either the script calls echo $OUTPUT-&amp;gt;header OR a moodleform is instantiated.&lt;br /&gt;
&lt;br /&gt;
==Related API&#039;s==&lt;br /&gt;
There are a couple of API&#039;s that are closely related to the Page API that you should be aware of as well.&lt;br /&gt;
&lt;br /&gt;
===Output API===&lt;br /&gt;
The output API is an immediate relation of the page API. The page API is about setting things up, whereas the output API is all about displaying things.&lt;br /&gt;
It&#039;s through the output API that content is actually produced, and much of the information you set up through the page is used to customise what is produced, and fill in the general blanks of any page (such as title and heading.&lt;br /&gt;
&lt;br /&gt;
See the [[Output API]] documentation for more information.&lt;br /&gt;
&lt;br /&gt;
===Page requirements API===&lt;br /&gt;
The page requirements API allows you the developer to include additional CSS, and JavaScript resources that should be included with the page, and to include JavaScript calls within the page through a variety of means.&lt;br /&gt;
Technically this API is part of the Output API mentioned above, however it deserves special mention. If you are going to be using any JavaScript or CSS within your page you will need to know about this.&lt;br /&gt;
&lt;br /&gt;
See the [[Output API]] documentation for more information on the page requirements API.&lt;br /&gt;
&lt;br /&gt;
===Navigation API===&lt;br /&gt;
The final API to mention is the navigation API. This again is integral to both the page and output API and is used to recognise the context of the content being displayed and ensure that the correct blocks and navigaiton structure are loaded for the context.&lt;br /&gt;
There is a good chance that you will encounter a need to customise the navigation early on in plugin page development and it&#039;s important to be aware of this important API.&lt;br /&gt;
&lt;br /&gt;
See the [[Navigation API]] documentation for more information on the page requirements API.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Core APIs]] : A list of all the core API&#039;s in Moodle.&lt;br /&gt;
* [[Output API]] : The Output API.&lt;br /&gt;
* [[Navigation API]] : The Navigation API.&lt;br /&gt;
* [http://moodle.org/mod/forum/view.php?id=55 General developer forum] : The place to ask question you may have about the Page API.&lt;br /&gt;
* MDL-30977 : The issue to see the Page API properly documented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:API]]&lt;/div&gt;</summary>
		<author><name>Simontite</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Blocks&amp;diff=34336</id>
		<title>Blocks</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Blocks&amp;diff=34336"/>
		<updated>2012-06-28T11:48:22Z</updated>

		<summary type="html">&lt;p&gt;Simontite: /* See also */ Blocks Advanced A continuation of this tutorial.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039; A Step-by-step Guide To Creating Blocks &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Original Author: Jon Papaioannou ([mailto:pj@moodle.org pj@moodle.org])&lt;br /&gt;
&lt;br /&gt;
Updated to Moodle 2.0 and above by: Greg J Preece ([mailto:greg.preece@blackboard.com greg.preece@blackboard.com])&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
The present document serves as a guide to developers who want to create their own blocks for use in Moodle. It applies to the 2.0 development version of Moodle (and any newer) &#039;&#039;&#039;only&#039;&#039;&#039;, as the blocks API changed significantly enough to warrant new documentation. Those wishing to read the old tutorial for Moodles 1.5 to 1.9 can find it under [[Blocks/Blocks for 1.5 to 1.9| Blocks for 1.5 to 1.9]].&lt;br /&gt;
&lt;br /&gt;
The guide is written as an interactive course which aims to develop a configurable, multi-purpose block that displays arbitrary HTML. It&#039;s targeted mainly at people with little experience with Moodle or programming in general and aims to show how easy it is to create new blocks for Moodle. A certain small amount of PHP programming knowledge is still required, though. &lt;br /&gt;
&lt;br /&gt;
Experienced developers and those who just want a &#039;&#039;&#039;programmer&#039;s reference&#039;&#039;&#039; text should refer to [[Blocks/Appendix_A| Appendix A]] because the main guide has a rather low concentration of pure information in the text.&lt;br /&gt;
&lt;br /&gt;
== Basic Concepts ==&lt;br /&gt;
&lt;br /&gt;
Through this guide, we will be following the creation of an &amp;quot;HTML&amp;quot; block from scratch in order to demonstrate most of the block features at our disposal. Our block will be named &amp;quot;SimpleHTML&amp;quot;. This does not constrain us regarding the name of the actual directory on the server where the files for our block will be stored, but for consistency we will follow the practice of using the lowercased form &amp;quot;simplehtml&amp;quot; in any case where such a name is required. &lt;br /&gt;
&lt;br /&gt;
Whenever we refer to a file or directory name which contains &amp;quot;simplehtml&amp;quot;, it&#039;s important to remember that &#039;&#039;only&#039;&#039; the &amp;quot;simplehtml&amp;quot; part is up to us to change; the rest is standardised and essential for Moodle to work correctly.&lt;br /&gt;
&lt;br /&gt;
Whenever a file&#039;s path is mentioned in this guide, it will always start with a slash. This refers to the Moodle home directory; all files and directories will be referred to with respect to that directory.&lt;br /&gt;
&lt;br /&gt;
== Ready, Set, Go! ==&lt;br /&gt;
&lt;br /&gt;
To define a &amp;quot;block&amp;quot; in Moodle, in the most basic case we need to provide just three PHP files:&lt;br /&gt;
&lt;br /&gt;
; /blocks/simplehtml/block_simplehtml.php : This file will hold the class definition for the block, and is used both to manage it as a plugin and to render it onscreen.&lt;br /&gt;
&lt;br /&gt;
; /blocks/simplehtml/version.php : This file will hold version information for the plugin, along with other advanced parameters (not covered here - see [[version.php]] if you want more details).&lt;br /&gt;
&lt;br /&gt;
; /blocks/simplehtml/lang/en/block_simplehtml.php : This is the English language file for your block. If you are not an English speaker, you can replace &#039;en&#039; with your appropriate language code. All language files for blocks go under the /lang subfolder of the block&#039;s installation folder.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We start by creating the directory &#039;&#039;/blocks/simplehtml/&#039;&#039; and creating the main object file, &#039;&#039;/blocks/simplehtml/&#039;&#039;&#039;&#039;&#039;block_simplehtml.php&#039;&#039;&#039;. We then begin coding the block:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
class block_simplehtml extends block_base {&lt;br /&gt;
    public function init() {&lt;br /&gt;
        $this-&amp;gt;title = get_string(&#039;simplehtml&#039;, &#039;block_simplehtml&#039;);&lt;br /&gt;
    }&lt;br /&gt;
    // The PHP tag and the curly bracket for the class definition &lt;br /&gt;
    // will only be closed after there is another function added in the next section.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first line is our block class definition; it must be named exactly in the manner shown. Again, only the &amp;quot;simplehtml&amp;quot; part can (and indeed must) change; everything else is standardised.&lt;br /&gt;
&lt;br /&gt;
Our class is then given a small method: [[Blocks/Appendix_A#init.28.29| init()]]. This is essential for all blocks, and its purpose is to give values to any class member variables that need instantiating. &lt;br /&gt;
&lt;br /&gt;
In this very basic example, we only want to set [[Blocks/Appendix_A#.24this-.3Etitle| $this-&amp;gt;title]], which is the title displayed in the header of our block. We can set it to whatever we like; in this case it&#039;s set to read the actual title from the language file mentioned previously, which is then distributed along with the block. I&#039;ll skip ahead a bit here and say that if you want your block to display &#039;&#039;&#039;no&#039;&#039;&#039; title at all, then you should set this to any descriptive value you want (but &#039;&#039;&#039;not&#039;&#039;&#039; make it an empty string). We will later see [[Blocks#Eye_Candy|how to disable the title&#039;s display]].&lt;br /&gt;
&lt;br /&gt;
The second file we will need to construct our block skeleton is a version file. Prior to Moodle 2.0, version details for blocks were stored as class fields; as of Moodle 2.0 these are stored in a file called version.php, stored under &#039;&#039;/blocks/simplehtml/&#039;&#039;&#039;version.php&#039;&#039;&#039;&#039;&#039;. The version file is very simple indeed, containing only a few field definitions, depending on your needs. Here is an example:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $plugin-&amp;gt;version = 2011062800;  // YYYYMMDDHH (year, month, day, 24-hr time)&lt;br /&gt;
    $plugin-&amp;gt;requires = 2010112400; // YYYYMMDDHH (This is the release version for Moodle 2.0)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains object field definitions that denote the version number of the block, along with the minimum version of Moodle that must be installed in order to use it. Please note that the object being used here is &#039;&#039;always&#039;&#039; called &#039;&#039;&#039;$plugin&#039;&#039;&#039;, and that you do not need to create this object yourself within the version file. Note also that we didnt include the closing &amp;quot;?&amp;gt;&amp;quot; tag for PHP. This is intentional, and a [[Coding_style#PHP_tags | workaround for whitespace issues]].&lt;br /&gt;
&lt;br /&gt;
Moodle 2.0 and above also require a name for our plugin to show in the upgrading page. We set this value, along with any other language strings we wish to use within the block, in a language package as previously mentioned (the same file where we put our string for the plugin title). Now we will create this language package. Create the file &#039;&#039;/blocks/simplehtml/lang/en/&#039;&#039;&#039;&#039;&#039;block_simplehtml.php&#039;&#039;&#039; and paste the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
    $string[&#039;pluginname&#039;] = &#039;Simple html block&#039;;&lt;br /&gt;
    $string[&#039;simplehtml&#039;] = &#039;Simple html&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
== I Just Hear Static ==&lt;br /&gt;
In order to get our block to actually display something on screen, we need to add one more method to our class (before the final closing brace in our file). The new code is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;  &lt;br /&gt;
  public function get_content() {&lt;br /&gt;
    if ($this-&amp;gt;content !== null) {&lt;br /&gt;
      return $this-&amp;gt;content;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $this-&amp;gt;content         =  new stdClass;&lt;br /&gt;
    $this-&amp;gt;content-&amp;gt;text   = &#039;The content of our SimpleHTML block!&#039;;&lt;br /&gt;
    $this-&amp;gt;content-&amp;gt;footer = &#039;Footer here...&#039;;&lt;br /&gt;
 &lt;br /&gt;
    return $this-&amp;gt;content;&lt;br /&gt;
  }&lt;br /&gt;
}   // Here&#039;s the closing bracket for the class definition&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can&#039;t get any simpler than that, can it? Let&#039;s dissect this method to see what&#039;s going on...&lt;br /&gt;
&lt;br /&gt;
First of all, there is a check that returns the current value of [[Blocks/Appendix_A#.24this-.3Econtent| $this-&amp;gt;content]] if it&#039;s not NULL; otherwise we proceed with &amp;quot;computing&amp;quot; it. Since the computation is potentially a time-consuming operation and it &#039;&#039;&#039;will&#039;&#039;&#039; be called several times for each block (Moodle works that way internally), we take a precaution and include this time-saver.&lt;br /&gt;
Supposing the content had not been computed before (it was NULL), we then define it from scratch. The code speaks for itself there, so there isn&#039;t much to say. Just keep in mind that we can use HTML both in the text &#039;&#039;&#039;and&#039;&#039;&#039; in the footer, if we want to.&lt;br /&gt;
&lt;br /&gt;
It&#039;s worth mentioning that this is not the only type of content a block can output. You can also create lists and hierarchical trees, which are better suited for certain types of output, such as menus. These different content types have an impact on the content object and how it is constructed. For more information, see [[Blocks/Appendix A#.24this-.3Econtent_type|Appendix A]]&lt;br /&gt;
&lt;br /&gt;
At this point our block should be capable of being automatically installed in Moodle and added to courses; visit your administration page to install it (Click &amp;quot;Notifications&amp;quot; under the Site Administration Block) and after seeing it in action come back to continue our tutorial.&lt;br /&gt;
&lt;br /&gt;
== Configure That Out ==&lt;br /&gt;
&lt;br /&gt;
The current version of our block doesn&#039;t really do much; it just displays a fixed message, which is not very useful. What we&#039;d really like to do is allow the teachers to customize what goes into the block. This, in block-speak, is called &amp;quot;instance configuration&amp;quot;. Basic instance configuration is automatic in Moodle 2.0; if you put any page with blocks on it into &amp;quot;editing mode&amp;quot;, you will notice that each block has an edit button in its title bar. Clicking on this will take you to the block configuration form. The settings that Moodle adds to this form by default relate to the block&#039;s appearance and position on Moodle pages. &lt;br /&gt;
&lt;br /&gt;
We can extend this configuration form, and add custom preferences fields, so that users can better tailor our block to a given task or page. To extend the configuration form, create the file &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;/blocks/simplehtml/&#039;&#039;&#039;edit_form.php&#039;&#039;&#039;&amp;lt;/span&amp;gt;, and fill it with the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
class block_simplehtml_edit_form extends block_edit_form {&lt;br /&gt;
        &lt;br /&gt;
    protected function specific_definition($mform) {&lt;br /&gt;
        &lt;br /&gt;
        // Section header title according to language file.&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;header&#039;, &#039;configheader&#039;, get_string(&#039;blocksettings&#039;, &#039;block&#039;));&lt;br /&gt;
&lt;br /&gt;
        // A sample string variable with a default value.&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;text&#039;, &#039;config_text&#039;, get_string(&#039;blockstring&#039;, &#039;block_simplehtml&#039;));&lt;br /&gt;
        $mform-&amp;gt;setDefault(&#039;config_text&#039;, &#039;default value&#039;);&lt;br /&gt;
        $mform-&amp;gt;setType(&#039;config_text&#039;, PARAM_MULTILANG);        &lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
The first line declares a class that inherits &#039;&#039;&#039;from block_edit_form&#039;&#039;&#039;, and this allows Moodle to identify the code to execute in the configuration page. The &#039;&#039;&#039;specific_definition()&#039;&#039;&#039; method is where your form elements are defined, and these take the same format as with the standard [[lib/formslib.php_Form_Definition|Moodle form library]].  Within our specific_definition method, we have created a header, and an input field which will accept text to be used within the block.  &lt;br /&gt;
&lt;br /&gt;
IMPORTANT: All your field names need to start with &amp;quot;config_&amp;quot;, otherwise they will not be saved and will not be available within the block via [[Blocks/Appendix_A#.24this-.3Econfig| $this-&amp;gt;config]]. &lt;br /&gt;
&lt;br /&gt;
So once our instance configuration form has been saved, we can use the inputted text within the block like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (! empty($this-&amp;gt;config-&amp;gt;text)) {&lt;br /&gt;
    $this-&amp;gt;content-&amp;gt;text = $this-&amp;gt;config-&amp;gt;text;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that [[Blocks/Appendix_A#.24this-.3Econfig| $this-&amp;gt;config]] is available in all block methods &#039;&#039;except&#039;&#039; [[Blocks/Appendix_A#init.28.29|init()]]. This is because [[Blocks/Appendix_A#init.28.29|init()]] is called immediately as the block is being created, with the purpose of setting things up, so [[Blocks/Appendix_A#.24this-.3Econfig| $this-&amp;gt;config]] has not yet been instantiated.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note about Checkbox:&#039;&#039;&#039; You cannot use the &#039;checkbox&#039; element in the form (once set it will stay set). You must use advcheckbox instead. &lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
== The Specialists ==&lt;br /&gt;
&lt;br /&gt;
Implementing instance configuration for the block&#039;s contents was good enough to whet our appetite, but who wants to stop there? Why not customize the block&#039;s title, too?&lt;br /&gt;
&lt;br /&gt;
Why not, indeed. Well, our first attempt to achieve this is natural enough: let&#039;s add another field to &#039;&#039;/blocks/simplehtml/&#039;&#039;&#039;edit_form.php&#039;&#039;&#039;&#039;&#039;. Here goes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
    // A sample string variable with a default value.&lt;br /&gt;
    $mform-&amp;gt;addElement(&#039;text&#039;, &#039;config_title&#039;, get_string(&#039;blocktitle&#039;, &#039;block_simplehtml&#039;));&lt;br /&gt;
    $mform-&amp;gt;setDefault(&#039;config_title&#039;, &#039;default value&#039;);&lt;br /&gt;
    $mform-&amp;gt;setType(&#039;config_title&#039;, PARAM_MULTILANG);        &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We save the edited file, go to a course, edit the title of the block and... nothing happens! The instance configuration is saved correctly, all right (editing it once more proves that) but it&#039;s not being displayed. All we get is just the simple &amp;quot;SimpleHTML&amp;quot; title.&lt;br /&gt;
&lt;br /&gt;
That&#039;s not too weird, if we think back a bit. Do you remember that [[Blocks/Appendix_A#init.28.29|init()]] method, where we set [[Blocks/Appendix_A#.24this-.3Etitle|$this-&amp;gt;title]]? We didn&#039;t actually change its value from then, and [[Blocks/Appendix_A#.24this-.3Etitle|$this-&amp;gt;title]] is definitely not the same as &#039;&#039;&#039;$this-&amp;gt;config-&amp;gt;title&#039;&#039;&#039; (to Moodle, at least). What we need is a way to update [[Blocks/Appendix_A#.24this-.3Etitle|$this-&amp;gt;title]] with the value in the instance configuration. But as we said a bit earlier, we can use [[Blocks/Appendix_A#.24this-.3Econfig| $this-&amp;gt;config]] in all methods &#039;&#039;except&#039;&#039; [[Blocks/Appendix_A#init.28.29|init()]]! So what can we do?&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pull out another ace from our sleeve, and add this small method to our block class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public function specialization() {&lt;br /&gt;
  if (!empty($this-&amp;gt;config-&amp;gt;title)) {&lt;br /&gt;
    $this-&amp;gt;title = $this-&amp;gt;config-&amp;gt;title;&lt;br /&gt;
  } else {&lt;br /&gt;
    $this-&amp;gt;config-&amp;gt;title = &#039;Default title ...&#039;;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  if (empty($this-&amp;gt;config-&amp;gt;text)) {&lt;br /&gt;
    $this-&amp;gt;config-&amp;gt;text = &#039;Default text ...&#039;;&lt;br /&gt;
  }    &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Aha, here&#039;s what we wanted to do all along! But what&#039;s going on with the [[Blocks/Appendix_A#specialization.28.29| specialization()]] method?&lt;br /&gt;
&lt;br /&gt;
This &amp;quot;magic&amp;quot; method has actually a very nice property: it&#039;s &#039;&#039;guaranteed&#039;&#039; to be automatically called by Moodle as soon as our instance configuration is loaded and available (that is, immediately after [[Blocks/Appendix_A#init.28.29|init()]] is called). That means before the block&#039;s content is computed for the first time, and indeed before &#039;&#039;anything&#039;&#039; else is done with the block. Thus, providing a [[Blocks/Appendix_A#specialization.28.29| specialization()]] method is the natural choice for any configuration data that needs to be acted upon or made available &amp;quot;as soon as possible&amp;quot;, as in this case.&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
== Now You See Me, Now You Don&#039;t ==&lt;br /&gt;
&lt;br /&gt;
Now would be a good time to mention another nifty technique that can be used in blocks, and which comes in handy quite often. Specifically, it may be the case that our block will have something interesting to display some of the time; but in some other cases, it won&#039;t have anything useful to say. An example here would be the &amp;quot;Recent Activity&amp;quot; block, in the case where no recent activity in fact exists. &lt;br /&gt;
&lt;br /&gt;
However in that case the block chooses to explicitly inform you of the lack of said activity, which is arguably useful. It would be nice, then, to be able to have our block &amp;quot;disappear&amp;quot; if it&#039;s not needed to display it.&lt;br /&gt;
&lt;br /&gt;
This is indeed possible, and the way to do it is to make sure that after the [[Blocks/Appendix_A#get_content.28.29| get_content()]] method is called, the block has no content to display. This means that all fields in $this-&amp;gt;content should be equal to the empty string (&amp;lt;nowiki&amp;gt;&#039;&#039;&amp;lt;/nowiki&amp;gt;). In the case of our HTML-based block, these fields are $this-&amp;gt;content-&amp;gt;text and $this-&amp;gt;content-&amp;gt;footer. Moodle performs this check by calling the block&#039;s [[Blocks/Appendix_A#is_empty.28.29| is_empty()]] method, and if the block is indeed empty then it is not displayed at all.&lt;br /&gt;
&lt;br /&gt;
Note that the exact value of the block&#039;s title and the presence or absence of a [[Blocks/Appendix_A#hide_header.28.29| hide_header()]] method do &#039;&#039;not&#039;&#039; affect this behavior. A block is considered empty if it has no content, irrespective of anything else.&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
== We Are Legion ==&lt;br /&gt;
&lt;br /&gt;
Right now our block is fully configurable, both in title and content. It&#039;s so versatile, in fact, that we could make pretty much anything out of it. It would be really nice to be able to add multiple blocks of this type to a single course. And, as you might have guessed, doing that is as simple as adding another small method to our block class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public function instance_allow_multiple() {&lt;br /&gt;
  return true;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells Moodle that it should allow any number of instances of the SimpleHTML block in any course. After saving the changes to our file, Moodle immediately allows us to add multiple copies of the block without further ado!&lt;br /&gt;
&lt;br /&gt;
Please note that even if a block itself allows multiple instances in the same page, the administrator still has the option of disallowing such behavior. This setting can be set separately for each block from the Administration / Configuration / Blocks page.&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
== The Effects of Globalization ==&lt;br /&gt;
&lt;br /&gt;
Configuring each block instance with its own personal data is cool enough, but sometimes administrators need some way to &amp;quot;touch&amp;quot; all instances of a specific block at the same time. In the case of our SimpleHTML block, a few settings that would make sense to apply to all instances aren&#039;t that hard to come up with. &lt;br /&gt;
&lt;br /&gt;
For example, we might want to limit the contents of each block to only so many characters, or we might have a setting that filters HTML out of the block&#039;s contents, only allowing pure text in. Granted, such a feature wouldn&#039;t win us any awards for naming our block &amp;quot;SimpleHTML&amp;quot; but some tormented administrator somewhere might actually find it useful.&lt;br /&gt;
&lt;br /&gt;
This kind of configuration is called &amp;quot;global configuration&amp;quot; and applies only to a specific block type (all instances of that block type are affected, however).  Implementing such configuration for our block is quite similar to implementing the instance configuration. We will now see how to implement the second example, having a setting that only allows text and not HTML in the block&#039;s contents. To enable global configuration for the block, we create a new file, &#039;&#039;/blocks/simplehtml/&#039;&#039;&#039;settings.php&#039;&#039;&#039;&#039;&#039;, and populate it with form field definitions for each setting, which Moodle will use to generate and handle a global settings form.  This is quite similar in concept to how we generated the instance configuration form earlier, but the actual code used to generate the form and fields is somewhat different.&lt;br /&gt;
&lt;br /&gt;
Place the following in your settings.php file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$settings-&amp;gt;add(new admin_setting_heading(&lt;br /&gt;
            &#039;headerconfig&#039;,&lt;br /&gt;
            get_string(&#039;headerconfig&#039;, &#039;block_simplehtml&#039;),&lt;br /&gt;
            get_string(&#039;descconfig&#039;, &#039;block_simplehtml&#039;)&lt;br /&gt;
        ));&lt;br /&gt;
&lt;br /&gt;
$settings-&amp;gt;add(new admin_setting_configcheckbox(&lt;br /&gt;
            &#039;simplehtml/Allow_HTML&#039;,&lt;br /&gt;
            get_string(&#039;labelallowhtml&#039;, &#039;block_simplehtml&#039;),&lt;br /&gt;
            get_string(&#039;descallowhtml&#039;, &#039;block_simplehtml&#039;),&lt;br /&gt;
            &#039;0&#039;&lt;br /&gt;
        ));    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, to generate a global configuration form, we simply create admin setting objects and add them to an array. This array is then stepped over to create the settings form, and the inputted data is automatically saved to the database. Full details of the setting types available and how to add them can be found under [[Admin_settings#Individual_settings]].&lt;br /&gt;
&lt;br /&gt;
We&#039;ve now created a header and checkbox form element to accept configuration details from the site admin. You should pay extra attention to the name of our checkbox element, &#039;&#039;&#039; &#039;simplehtml/Allow_HTML&#039; &#039;&#039;&#039;, as it specifies not only the name of the configuration option, but also how it should be stored. If you simply specify a name for the config option, it will be stored in the global $CFG object, and in the &#039;&#039;&amp;lt;prefix&amp;gt;_config&#039;&#039; database table. This will make your config variable available immediately via $CFG without requiring an additional database call, but will also increase the size of the $CFG object. In addition, we must prefix the variable with the name of our block, otherwise we run the risk of our config variable sharing its name with a similar variable in another plugin, or within Moodle itself.&lt;br /&gt;
&lt;br /&gt;
The preferred method of storing your block&#039;s configuration data is to prefix each config variable name in your settings.php file with your block&#039;s name, followed by a slash ( / ), and the name of the configuration variable, as we have done above. If you write your settings.php file in this way, then your variables will be stored in the &#039;&#039;&amp;lt;prefix&amp;gt;_config_plugin&#039;&#039; table, under your block&#039;s name. Your config data will still be available via a &#039;&#039;&#039;get_config()&#039;&#039;&#039; call, and name collision will be impossible between plugins.&lt;br /&gt;
&lt;br /&gt;
Finally, if you&#039;re wondering why there are two language tags specified for each element, the first tag is for the element&#039;s label or primary text, and the second tag is for its description. And that&#039;s it. Pretty easy, huh?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE FOR UPGRADERS&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll notice that the settings.php file and parsed element names replaces Moodle&#039;s old storage method, wherein it would send all the configuration data to your block&#039;s [[Blocks/Appendix_A#config_save.28.29|config_save()]] method, and allow you to override how the data is saved. The [[Blocks/Appendix_A#config_save.28.29|config_save()]] method is no longer used in Moodle 2.x; however the [[Blocks/Appendix_A#instance_config_save.28.29|instance_config_save()]] method is very much alive and well, as you will see shortly.&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
=== Accessing Global Config Data  ===&lt;br /&gt;
&lt;br /&gt;
Now that we have global data defined for the plugin, we need to know how to access it within our code.  If you saved your config variables in the global namespace, you can access them from the global $CFG object, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$allowHTML = $CFG-&amp;gt;Allow_HTML;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If, as recommended, you saved your config variables in a custom namespace for your block, then you can access them via a call to &#039;&#039;&#039;get_config()&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$allowHTML = get_config(&#039;simplehtml&#039;, &#039;Allow_HTML&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
=== Rolling It All Together ===&lt;br /&gt;
&lt;br /&gt;
OK, so we now have an instance configuration form that allows users to enter custom content text for a block, and a global configuration option that dictates whether or not that user should be allowed to enter HTML tags as part of the content. Now we just need to tie the two together. But if Moodle takes care of the form processing for our instance configuration in edit_form.php, how can we capture it and remove the HTML tags where required?&lt;br /&gt;
&lt;br /&gt;
Well, fortunately, there is a way this can be done.  By overriding the [[Blocks/Appendix_A#instance_config_save.28.29| instance_config_save()]] method in our block class, we can modify the way in which instance configuration data is stored after input. The default implementation is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public function instance_config_save($data) {&lt;br /&gt;
  $data = stripslashes_recursive($data);&lt;br /&gt;
  $this-&amp;gt;config = $data;&lt;br /&gt;
  return set_field(&#039;block_instance&#039;, &lt;br /&gt;
                   &#039;configdata&#039;,&lt;br /&gt;
                    base64_encode(serialize($data)),&lt;br /&gt;
                   &#039;id&#039;, &lt;br /&gt;
                   $this-&amp;gt;instance-&amp;gt;id);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may look intimidating at first (what&#039;s all this stripslashes_recursive() and base64_encode() and serialize() stuff?) but do not despair; we won&#039;t have to touch any of it. We will only add some extra validation code in the beginning and then instruct Moodle to additionally call this default implementation to do the actual storing of the data. Specifically, we will add a method to our class which goes like this:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public function instance_config_save($data) {&lt;br /&gt;
  if(get_config(&#039;simplehtml&#039;, &#039;Allow_HTML&#039;) == &#039;1&#039;) {&lt;br /&gt;
    $data-&amp;gt;text = strip_tags($data-&amp;gt;text);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // And now forward to the default implementation defined in the parent class&lt;br /&gt;
  return parent::instance_config_save($data);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(This example assumes you are using a custom namespace for the block.)&lt;br /&gt;
&lt;br /&gt;
At last! Now the administrator has absolute power of life and death over what type of content is allowed in our &amp;quot;SimpleHTML&amp;quot; block! Absolute? Well... not exactly. In fact, if we think about it for a while, it will become apparent that if at some point in time HTML is allowed and some blocks have saved their content with HTML included, and afterwards the administrator changes the setting to &amp;quot;off&amp;quot;, this will only prevent subsequent content changes from including HTML. Blocks which already had HTML in their content would continue to display it!&lt;br /&gt;
&lt;br /&gt;
Following that train of thought, the next stop is realizing that we wouldn&#039;t have this problem if we had chosen the lazy approach a while back, because in that case we would &amp;quot;sanitize&amp;quot; each block&#039;s content just before it was displayed. &lt;br /&gt;
&lt;br /&gt;
The only thing we can do with the eager approach is strip all the tags from the content of all SimpleHTML instances as soon as the admin setting is changed to &amp;quot;HTML off&amp;quot;; but even then, turning the setting back to &amp;quot;HTML on&amp;quot; won&#039;t bring back the tags we stripped away. On the other hand, the lazy approach might be slower, but it&#039;s more versatile; we can choose whether to strip or keep the HTML before displaying the content, and we won&#039;t lose it at all if the admin toggles the setting off and on again. Isn&#039;t the life of a developer simple and wonderful?&lt;br /&gt;
&lt;br /&gt;
=== Exercise === &lt;br /&gt;
We will let this part of the tutorial come to a close with the obligatory exercise for the reader: &lt;br /&gt;
In order to have the SimpleHTML block work &amp;quot;correctly&amp;quot;, find out how to strengthen the eager approach to strip out all tags from the existing configuration of all instances of our block, &#039;&#039;&#039;or&#039;&#039;&#039; go back and implement the lazy approach instead. &lt;br /&gt;
(Hint: Do that in the [[Blocks/Appendix_A#get_content.28.29| get_content()]] method.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
== Eye Candy ==&lt;br /&gt;
&lt;br /&gt;
Our block is just about complete functionally, so now let&#039;s take a look at some of the tricks we can use to make its behavior customized in a few more useful ways.&lt;br /&gt;
&lt;br /&gt;
First of all, there are a couple of ways we can adjust the visual aspects of our block. For starters, it might be useful to create a block that doesn&#039;t display a header (title) at all. You can see this effect in action in the Course Description block that comes with Moodle. This behavior is achieved by, you guessed it, adding one more method to our block class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public function hide_header() {&lt;br /&gt;
  return true;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One more note here: we cannot just set an empty title inside the block&#039;s [[Blocks/Appendix_A#init.28.29| init()]] method; it&#039;s necessary for each block to have a unique, non-empty title after [[Blocks/Appendix_A#init.28.29| init()]] is called so that Moodle can use those titles to differentiate between all of the installed blocks.&lt;br /&gt;
&lt;br /&gt;
Next, we can affect some properties of the actual HTML that will be used to print our block. Each block is fully contained within a &amp;amp;lt;div&amp;amp;gt; or &amp;amp;lt;table&amp;amp;gt; elements, inside which all the HTML for that block is printed. We can instruct Moodle to add HTML attributes with specific values to that container. This is generally done to give us freedom to customize the end result using CSS (this is in fact done by default as we&#039;ll see below).&lt;br /&gt;
&lt;br /&gt;
The default behavior of this feature in our case will modify our block&#039;s &amp;quot;class&amp;quot; HTML attribute by appending the value &amp;quot;block_simplehtml&amp;quot; (the prefix &amp;quot;block_&amp;quot; followed by the name of our block, lowercased). We can then use that class to make CSS selectors in our theme to alter this block&#039;s visual style (for example, &amp;quot;.block_simplehtml { border: 1px black solid}&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
To change the default behavior, we will need to define a method which returns an associative array of attribute names and values. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public function html_attributes() {&lt;br /&gt;
    $attributes = parent::html_attributes(); // Get default values&lt;br /&gt;
    $attributes[&#039;class&#039;] .= &#039; block_&#039;. $this-&amp;gt;name(); // Append our class to class attribute&lt;br /&gt;
    return $attributes;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This results in the block having all its normal HTML attributes, as inherited from the base block class, plus our additional class name. We can now use this class name to change the style of the block, add JavaScript events to it via YUI, and so on. And for one final elegant touch,  we have not set the class to the hard-coded value &amp;quot;block_simplehtml&amp;quot;, but instead used the [[Blocks/Appendix_A#name.28.29| name()]] method to make it dynamically match our block&#039;s name.&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
== Authorized Personnel Only ==&lt;br /&gt;
&lt;br /&gt;
Some blocks are useful in some circumstances, but not in others. An example of this would be the &amp;quot;Social Activities&amp;quot; block, which is useful in courses with the &amp;quot;social&amp;quot; course format, but not courses with the &amp;quot;weeks&amp;quot; format. What we need to be able to do is limit our block&#039;s availability, so that it can only be selected on pages where its content or abilities are appropriate.&lt;br /&gt;
&lt;br /&gt;
Moodle allows us to declare which page formats a block is available on, and enforces these restrictions as set by the block&#039;s developer at all times. The information is given to Moodle as a standard associative array, with each key corresponding to a page format and defining a boolean value (true/false) that declares whether the block should be allowed to appear in that page format.&lt;br /&gt;
&lt;br /&gt;
Notice the deliberate use of the term &#039;&#039;page&#039;&#039; instead of &#039;&#039;course&#039;&#039; in the above paragraph. This is because in Moodle 1.5 and onwards, blocks can be displayed in any page that supports them. The best example of such pages are the course pages, but we are not restricted to them. For instance, the quiz view page (the first one we see when we click on the name of the quiz) also supports blocks.&lt;br /&gt;
&lt;br /&gt;
The format names we can use for the pages derive from the name of the script which is actually used to display that page. For example, when we are looking at a course, the script is &amp;lt;span class=&amp;quot;filename&amp;quot;&amp;gt;/course/view.php&amp;lt;/span&amp;gt; (this is evident from the browser&#039;s address line). Thus, the format name of that page is &#039;&#039;&#039;course-view&#039;&#039;&#039;. It follows easily that the format name for a quiz view page is &#039;&#039;&#039;mod-quiz-view&#039;&#039;&#039;. This rule of thumb does have a few exceptions, however:&lt;br /&gt;
&lt;br /&gt;
# The format name for the front page of Moodle is &#039;&#039;&#039;site-index&#039;&#039;&#039;.&lt;br /&gt;
# The format name for courses is actually not just &#039;&#039;&#039;course-view&#039;&#039;&#039;&amp;lt;nowiki&amp;gt;; it is &amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;course-view-weeks&#039;&#039;&#039;, &#039;&#039;&#039;course-view-topics&#039;&#039;&#039;, etc.&lt;br /&gt;
# Even though there is no such page, the format name &#039;&#039;&#039;all&#039;&#039;&#039; can be used as a catch-all option.&lt;br /&gt;
&lt;br /&gt;
We can include as many format names as we want in our definition of the applicable formats. Each format can be allowed or disallowed, and there are also three more rules that help resolve the question &amp;quot;is this block allowed into this page or not?&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
# Prefixes of a format name will match that format name; for example, &#039;&#039;&#039;mod&#039;&#039;&#039; will match all the activity modules. &#039;&#039;&#039;course-view&#039;&#039;&#039; will match any course, regardless of the course format. And finally, &#039;&#039;&#039;site&#039;&#039;&#039; will also match the front page (remember that its full format name is &#039;&#039;&#039;site-index&#039;&#039;&#039;).&lt;br /&gt;
# The more specialized a format name that matches our page is, the higher precedence it has when deciding if the block will be allowed. For example, &#039;&#039;&#039;mod&#039;&#039;&#039;, &#039;&#039;&#039;mod-quiz&#039;&#039;&#039; and &#039;&#039;&#039;mod-quiz-view&#039;&#039;&#039; all match the quiz view page. But if all three are present, &#039;&#039;&#039;mod-quiz-view&#039;&#039;&#039; will take precedence over the other two because it is a better match.&lt;br /&gt;
# The character &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039; can be used in place of any word. For example, &#039;&#039;&#039;mod&#039;&#039;&#039; and &#039;&#039;&#039;mod-*&#039;&#039;&#039; are equivalent. At the time of this document&#039;s writing, there is no actual reason to utilize this &amp;quot;wildcard matching&amp;quot; feature, but it exists for future usage.&lt;br /&gt;
# The order that the format names appear does not make any difference.&lt;br /&gt;
All of the above are enough to make the situation sound complex, so let&#039;s look at some specific examples. First of all, to have our block appear &#039;&#039;&#039;only&#039;&#039;&#039; in the site front page, we would use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt; &lt;br /&gt;
public function applicable_formats() {&lt;br /&gt;
  return array(&#039;site&#039; =&amp;gt; true);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Since &#039;&#039;&#039;all&#039;&#039;&#039; is missing, the block is disallowed from appearing in &#039;&#039;any&#039;&#039; course format; but then &#039;&#039;&#039;site&#039;&#039;&#039; is set to TRUE, so it&#039;s explicitly allowed to appear in the site front page (remember that &#039;&#039;&#039;site&#039;&#039;&#039; matches &#039;&#039;&#039;site-index&#039;&#039;&#039; because it&#039;s a prefix).&lt;br /&gt;
&lt;br /&gt;
For another example, if we wanted to allow the block to appear in all course formats &#039;&#039;except&#039;&#039; social, and also to &#039;&#039;not&#039;&#039; be allowed anywhere but in courses, we would use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt; &lt;br /&gt;
public function applicable_formats() {&lt;br /&gt;
  return array(&lt;br /&gt;
           &#039;course-view&#039; =&amp;gt; true, &lt;br /&gt;
    &#039;course-view-social&#039; =&amp;gt; false);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This time, we first allow the block to appear in all courses and then we explicitly disallow the social format.&lt;br /&gt;
For our final, most complicated example, suppose that a block can be displayed in the site front page, in courses (but not social courses) and also when we are viewing any activity module, &#039;&#039;except&#039;&#039; quiz. This would be:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public function applicable_formats() {&lt;br /&gt;
  return array(&lt;br /&gt;
           &#039;site-index&#039; =&amp;gt; true,&lt;br /&gt;
          &#039;course-view&#039; =&amp;gt; true, &lt;br /&gt;
   &#039;course-view-social&#039; =&amp;gt; false,&lt;br /&gt;
                  &#039;mod&#039; =&amp;gt; true, &lt;br /&gt;
             &#039;mod-quiz&#039; =&amp;gt; false&lt;br /&gt;
  );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is not difficult to realize that the above accomplishes the objective if we remember that there is a &amp;quot;best match&amp;quot; policy to determine the end result.&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
== Responding to Cron ==&lt;br /&gt;
&lt;br /&gt;
It is possible to have our block respond to the global Moodle cron process; we can have a method that is run at regular intervals regardless of user interaction. There are two parts to this. Firstly we need to define a new function within our block class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public function cron() {&lt;br /&gt;
    mtrace( &amp;quot;Hey, my cron script is running&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
    // do something&lt;br /&gt;
&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we will need to set the (minimum) execution interval for our cron function. Prior to Moodle 2.0, this was achieved by setting the value of a block&#039;s $this-&amp;gt;cron field, via the init() method. This is now achieved by adding an additional line to our &#039;&#039;/blocks/simplehtml/&#039;&#039;&#039;version.php&#039;&#039;&#039;&#039;&#039; file. Open it up and add the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
    $plugin-&amp;gt;cron = 300;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cron intervals are set in seconds, so the above line will set our minimum execution interval to 5 minutes. However, the function can only be called as frequently as cron has been set to run in the Moodle installation. So if our block is set to wait at least 5 minutes between runs, as in this example, but Moodle&#039;s cron system is only set to run every 24 hours, then our block is going to be waiting a lot longer between runs than we expected!&lt;br /&gt;
&lt;br /&gt;
Remember that if we change any values in the version file or block file we &#039;&#039;&#039;must&#039;&#039;&#039; bump the version number and visit the Notifications page to upgrade the block, otherwise they will be ignored.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039;&lt;br /&gt;
The block cron is designed to call the cron script for that block &#039;&#039;&#039;type&#039;&#039;&#039; only. That is, cron does not care about individual instances of blocks. Inside your cron function &#039;&#039;$this&#039;&#039; is defined, but it has almost nothing in it (only title and content fields are populated). If you need to execute cron for individual instances it is your own responsibility to iterate over them in the block&#039;s cron function. Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
public function cron() {&lt;br /&gt;
&lt;br /&gt;
    global $DB; // Global database object&lt;br /&gt;
&lt;br /&gt;
    // Get the instances of the block&lt;br /&gt;
    $instances = $DB-&amp;gt;get_records( &#039;block_instance&#039;, array(&#039;blockid&#039;=&amp;gt;&#039;simplehtml&#039;) );&lt;br /&gt;
&lt;br /&gt;
    // Iterate over the instances&lt;br /&gt;
    foreach ($instances as $instance) {&lt;br /&gt;
&lt;br /&gt;
        // Recreate block object&lt;br /&gt;
        $block = block_instance(&#039;simplehtml&#039;, $instance);&lt;br /&gt;
&lt;br /&gt;
        // $block is now the equivalent of $this in &#039;normal&#039; block&lt;br /&gt;
        // usage, e.g.&lt;br /&gt;
        $someconfigitem = $block-&amp;gt;config-&amp;gt;item2;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
TIP: This also means that creating a block is a possible way to create code that can respond to cron with a reasonably low overhead. No actual instances of the block are required.&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
== Additional Content Types == &lt;br /&gt;
&lt;br /&gt;
=== Lists ===&lt;br /&gt;
&lt;br /&gt;
In this final part of the guide we will briefly discuss several additional capabilities of Moodle&#039;s block system, namely the ability to create blocks that display different kinds of content to the user. The first of these creates a list of options and displays them to the user.  This list is displayed with one item per line, and an optional image (icon) next to the item. An example of such a &#039;&#039;list block&#039;&#039; is the standard Moodle &amp;quot;admin&amp;quot; block, which illustrates all the points discussed in this section.&lt;br /&gt;
&lt;br /&gt;
As we have seen so far, blocks use two properties of [[Blocks/Appendix_A#.24this-.3Econtent| $this-&amp;gt;content]]: &amp;quot;text&amp;quot; and &amp;quot;footer&amp;quot;. The text is displayed as-is as the block content, and the footer is displayed below the content in a smaller font size. List blocks use $this-&amp;gt;content-&amp;gt;footer in the exact same way, but they ignore $this-&amp;gt;content-&amp;gt;text.&lt;br /&gt;
&lt;br /&gt;
Instead, Moodle expects such blocks to set two other properties when the [[Blocks/Appendix_A#get_content.28.29| get_content()]] method is called: $this-&amp;gt;content-&amp;gt;items and $this-&amp;gt;content-&amp;gt;icons. $this-&amp;gt;content-&amp;gt;items should be a numerically indexed array containing elements that represent the HTML for each item in the list that is going to be displayed. Usually these items will be HTML anchor tags which provide links to some page. $this-&amp;gt;content-&amp;gt;icons should also be a numerically indexed array, with exactly as many items as $this-&amp;gt;content-&amp;gt;items has. Each of these items should be a fully qualified HTML &amp;lt;img&amp;gt; tag, with &amp;quot;src&amp;quot;, &amp;quot;height&amp;quot;, &amp;quot;width&amp;quot; and &amp;quot;alt&amp;quot; attributes. Obviously, it makes sense to keep the images small and of a uniform size. We would recommend standard 16x16 images for this purpose.&lt;br /&gt;
&lt;br /&gt;
In order to tell Moodle that we want to have a list block instead of the standard text block, we need to make a small change to our block class declaration. Instead of extending class &#039;&#039;&#039;block_base&#039;&#039;&#039;, our block will extend class &#039;&#039;&#039;block_list&#039;&#039;&#039;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt; &lt;br /&gt;
class block_my_menu extends block_list {&lt;br /&gt;
     // The init() method does not need to change at all&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In addition to making this change, we must of course also modify the [[Blocks/Appendix_A#get_content.28.29| get_content()]] method to construct the [[Blocks/Appendix_A#.24this-.3Econtent| $this-&amp;gt;content]] variable as discussed above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt; &lt;br /&gt;
public function get_content() {&lt;br /&gt;
  if ($this-&amp;gt;content !== null) {&lt;br /&gt;
    return $this-&amp;gt;content;&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  $this-&amp;gt;content         = new stdClass;&lt;br /&gt;
  $this-&amp;gt;content-&amp;gt;items  = array();&lt;br /&gt;
  $this-&amp;gt;content-&amp;gt;icons  = array();&lt;br /&gt;
  $this-&amp;gt;content-&amp;gt;footer = &#039;Footer here...&#039;;&lt;br /&gt;
 &lt;br /&gt;
  $this-&amp;gt;content-&amp;gt;items[] = html_writer::tag(&#039;a&#039;, &#039;Menu Option 1&#039;, array(&#039;href&#039; =&amp;gt; &#039;some_file.php&#039;));&lt;br /&gt;
  $this-&amp;gt;content-&amp;gt;icons[] = html_writer::empty_tag(&#039;img&#039;, array(&#039;src&#039; =&amp;gt; &#039;images/icons/1.gif&#039;, &#039;class&#039; =&amp;gt; &#039;icon&#039;));&lt;br /&gt;
&lt;br /&gt;
  // Add more list items here&lt;br /&gt;
 &lt;br /&gt;
  return $this-&amp;gt;content;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To summarise, if we want to create a list block instead of a text block, we just need to change the block class declaration and the [[Blocks/Appendix_A#get_content.28.29| get_content()]] method. Adding the mandatory [[Blocks/Appendix_A#init.28.29| init()]] method as discussed earlier will then give us our first list block in no time!&lt;br /&gt;
&lt;br /&gt;
=== Trees ===&lt;br /&gt;
&lt;br /&gt;
As of 23rd December 2011, this functionality remains inoperable in all Moodle 2.x versions. It appears that classes are missing from the code base. This has been added to the tracker at the URL below. Please upvote this issue if you require this functionality.&lt;br /&gt;
&lt;br /&gt;
[http://tracker.moodle.org/browse/MDL-28289 Visit this issue on the tracker @ MDL28289]&lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
== Database support ==&lt;br /&gt;
In case we need to have a database table that holds some specific information used within our block, we will need to create the file &#039;&#039;/blocks/simplehtml/&#039;&#039;&#039;install.xml&#039;&#039;&#039;&#039;&#039; with the table schema contained within it.&lt;br /&gt;
&lt;br /&gt;
To create the install.xml file, use the [[XMLDB editor]]. See [[Database_FAQ#XMLDB|Database FAQ &amp;gt; XMLDB]] for further details.&lt;br /&gt;
&lt;br /&gt;
Up-to-date documentation on upgrading our block, as well as providing new capabilities and events to the system, can be found under [https://docs.moodle.org/dev/Installing_and_upgrading_plugin_database_tables#install.php Installing and Upgrading Plugin Database Tables]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Blocks Advanced]] A continuation of this tutorial.&lt;br /&gt;
* [http://dev.moodle.org/mod/resource/view.php?id=48 Unit 7 of the Introduction to Moodle Programming course] is a follow up to this course. (But you should follow the forum discussions of that course closely as there are still some bugs and inconsistencies.)&lt;br /&gt;
* A [http://cvs.moodle.org/contrib/plugins/blocks/NEWBLOCK/ NEWBLOCK template] you can all use to start you own block.&lt;br /&gt;
&lt;br /&gt;
== Appendices ==&lt;br /&gt;
&lt;br /&gt;
The appendices have been moved to separate pages:&lt;br /&gt;
&lt;br /&gt;
* Appendix A: [[Blocks/Appendix A|&#039;&#039;block_base&#039;&#039; Reference]] &lt;br /&gt;
&lt;br /&gt;
{{Top}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Blocks]]&lt;br /&gt;
[[Category:Tutorial]]&lt;br /&gt;
&lt;br /&gt;
[[es:Desarrollo de bloques]]&lt;br /&gt;
[[ja:開発:ブロック]]&lt;br /&gt;
[[:en:Blocks|Blocks]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Plugins]]&lt;/div&gt;</summary>
		<author><name>Simontite</name></author>
	</entry>
</feed>