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
m (Added ref to file where source code is)
Line 1: Line 1:
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).
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.
There is no documentation for most of this class. Please look at the source code in moodle/lib/outputcomponents.php


== div, span methods ==
== div, span methods ==

Revision as of 02:14, 29 April 2016

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.