Note:

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

html writer: Difference between revisions

From MoodleDocs
No edit summary
(Added reference to xrefs and diffs page which documents methods of the class.)
Line 36: Line 36:


= References =
= References =
[[html writer | http://xref-diff.mukudu-dev.net/moodle32/lib/outputcomponents.php.html#html_writer]]
[[phpcrossref.com/xref/moodle/lib/outputcomponents.php.html]]
[[phpcrossref.com/xref/moodle/lib/outputcomponents.php.html]]


[[Category: Development]]
[[Category: Development]]

Revision as of 20:56, 6 December 2018

Usage

Moodle has a class called html_writer which allows you to output basic HTML tags. This is typically used within renderer functions, for example question/type/pluginname/renderer.php.

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

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

Methods

the div method

Moodle 2.5


html_writer::div(content, class="", attributes="");

Attributes is a key-value array.

Example usage:

$out .= html_writer::div('anonymous');  // <div>anonymous</div>
$out .= html_writer::div('kermit', 'frog'); // <div class="frog">kermit</div>
$out .= html_writer::div('Mr', 'toad', array('id' => 'tophat')); // <div class="toad" id="tophat">Mr</div>

spans

$out .= html_writer::start_span('zombie') . 'BRAINS' . html_writer::end_span(); // <span class="zombie">BRAINS</span>

generic tags

html_writer::tag(tag_name, contents, attributes=null); html_writer::start_tag(tag_name, attributes=null;); html_writer::end_tag(tag_name); html_writer::empty_tag(tag_name, attributes=null); html_writer::nonempty_tag(tag_name, content, attributes=null); html_writer::attribute(name, value); html_writer;:attributes(attributes_array);

References

http://xref-diff.mukudu-dev.net/moodle32/lib/outputcomponents.php.html#html_writer

phpcrossref.com/xref/moodle/lib/outputcomponents.php.html