Skip to content
bpstr edited this page Oct 21, 2019 · 2 revisions

The Markup class provides a simple structure for any standard markup which can be later rendered as string.

Creating a markup

To make a markup, simply create a new instance of the desired class with 3 possible attributes:

  • Tag (required)
  • Contents (may be another markup, or a simple string)
  • Attributes (provided as associative array)
$markup = Markup::create('report', 'Lorem ipsum dolor sit amet.', ['created' => date('Y-m-d')]);

echo $markup; // <report created="2019-10-21">Lorem ipsum dolor sit amet.</report>

Chainable methods

All methods except render() will return the object itself, so may be chained until it is turned into a string.

$markup->content('footer_key', Markup::create('footer', 'Footer of the report.'))->attr('expires', 'never');
<report created="2019-10-21" expires="never">Lorem ipsum dolor sit amet.<footer>Footer of the report.</footer></report>

Rendering markups

Just turn the $markup instance into string or call the render() method:

echo $markup->render();

echo $markup;

var_dump( (string) $markup );
Clone this wiki locally