-
Notifications
You must be signed in to change notification settings - Fork 1
HTMLTag
Mistralys edited this page Jan 7, 2022
·
7 revisions
The HTMLTag
helper class can be used to generate individual HTML tags with an easy to use, chainable object-oriented API.
use AppUtils;
echo HTMLTag::create('code')
->addClass('preformatted')
->id('code-snippet')
->attr('data-format', 'pretty')
->content('Content here');
Output (formatted for readability):
<code class="preformatted" id="code-snippet" data-format="pretty">
Content here
</code>
use AppUtils;
echo HTMLTag::create('select')
->name('product')
->prop('multiple')
->renderOpen();
Output:
<select name="product" multiple>
use AppUtils;
echo HTMLTag::create('link')
->attr('rel', 'stylesheet')
->href('/path/to/stylesheet.css')
->setSelfClosing();
Output:
<link rel="stylesheet" href="/path/to/stylesheet.css">
When generating XHTML, the slash can be enabled globally:
use AppUtils;
HTMLTag::getGlobalOptions()->setSelfCloseSlash();
echo HTMLTag::create('link')
->attr('rel', 'stylesheet')
->href('/path/to/stylesheet.css')
->setSelfClosing();
Output:
<link rel="stylesheet" href="/path/to/stylesheet.css"/>
New here?
Have a look at the overview for a list of all helper classes available in the package.
Table of contents
Find the current page in the collapsible "Pages" list above, and expand the page, to view a table of contents.