Note:

This site is no longer used and is in read-only mode. Instead please go to our new Moodle Developer Resource site.

html writer: Difference between revisions

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


This will result in the following HTML from each line:
This will result in the following HTML from each line:

Revision as of 12:11, 5 March 2013

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.

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.