Note:

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

html writer

From MoodleDocs
Revision as of 02:14, 29 April 2016 by Richard Jones (talk | contribs) (Added ref to file where source code is)

Moodle has a class called html_writer which allows you to output basic HTML tags. This is typically used within renderer functions (or by naughty people in scripts which are outputting content without using a renderer).

There is no documentation for most of this class. Please look at the source code in moodle/lib/outputcomponents.php

div, span methods

Moodle 2.5


To allow shorter code when outputting the div and span tags with classes, div and span methods were added in Moodle 2.5.

Example usage:

$out .= html_writer::div('anonymous');
$out .= html_writer::div('kermit', 'frog');
$out .= html_writer::start_span('zombie') . 'BRAINS' . html_writer::end_span();
$out .= html_writer::div('Mr', 'toad', array('id' => 'tophat'));

This will result in the following HTML from each line:

<div>anonymous</div>
<div class="frog">kermit</div>
<span class="zombie">BRAINS</span>
<div class="toad" id="tophat">Mr</div>

For detailed usage information, see the source code.