HTML Builder



HTML Builder

Introduction

The html builder contains useful tools where you can create or customise html elements easily. To get started on using the html builder, you can instantiate it by calling the namespace.

use HTML;

Basic Usage

Entities

Convert an HTML string to entities:

echo HTML::entities('<i>Hello World!</i>');

Output:

&lt;i&gt;Hello World!&lt;/i&gt;

Decode

Convert entities to HTML characters:

echo HTML::decode('&lt;i&gt;Hello World!&lt;/i&gt;');

Output:

<i>Hello World!</i>

Script

Generate a link to a JavaScript file:

HTML::script($url, $attributes = array(), false);

Third parameter is for a secure url, setting it to true will generate a https url.

echo HTML::script('assets/js/example.js');

Output:

<script src="http://www.novaframework.dev/assets/js/example.js"></script>

Style

Generate a link to a CSS file:

HTML::style($url, $attributes = array(), false);

Third parameter is for a secure url, setting it to true will generate a https url.

echo HTML::style('assets/css/example.css');

Output:

<link media="all" type="text/css" rel="stylesheet" href="http://www.novaframework.dev/assets/css/example.css">

Image

Generate an HTML image element:

HTML::image($url, $alt, $attributes = array(), false);

Fourth parameter is for a secure url, setting it to true will generate a https url.

echo HTML::image('assets/images/nova.jpg');

Output:

<img src="http://www.novaframework.dev/assets/images/nova.jpg">

Link

Generate a HTML link:

HTML::link($url, $title, $attributes = array(), false);

Fourth parameter is for a secure url, setting it to true will generate a https url.

echo HTML::link('subpage', 'Subpage');

Output:

<a href="http://www.novaframework.dev/subpage">Subpage</a>

Secure Link

Generate a HTTPS HTML link:

HTML::secureLink($url, $title, $attributes = array());
echo HTML::secureLink('subpage', 'Subpage');

Output:

<a href="https://www.novaframework.dev/subpage">Subpage</a>

Link Asset

Generate a HTML link to an asset:

HTML::linkAsset($url, $title, $attributes = array(), false);

Secure Link Asset

Generate a HTTPS HTML link to an asset:

HTML::linkRoute($url, $title, $attributes = array());

Link Route

Generate a HTML link to a named route:

HTML::linkRoute($name, $title, $parameters = array(), $attributes = array());

Link Action

Generate a HTML link to a controller action:

HTML::linkAction($action, $title, $parameters = array(), $attributes = array());

Mail To

Generate a HTML link to an email address:

HTML::mailto($email, $title, $attributes = array());

Email

Obfuscate an e-mail address to prevent spam-bots from sniffing it:

echo HTML::email('example@novaframework.dev');

Output:

&#101;&#120;a&#109;p&#108;&#x65;&#x40;n&#x6f;&#118;&#97;f&#x72;&#x61;&#109;&#101;&#119;or&#x6b;.d&#x65;v

Ordered List

Generate an ordered list of items:


$list = [
    'PHP',
    'mySQL',
    'HTML',
    'CSS',
    'Bacon'
];

echo HTML::ol($list, $attributes = array());

Output:

<ol><li>PHP</li><li>mySQL</li><li>HTML</li><li>CSS</li><li>Bacon</li></ol>

Unordered List

Generate an un-ordered list of items:


$list = [
    'PHP',
    'mySQL',
    'HTML',
    'CSS',
    'Bacon'
];

echo HTML::ul($list, $attributes = array());

Output:

<ul><li>PHP</li><li>mySQL</li><li>HTML</li><li>CSS</li><li>Bacon</li></ul>

Obfuscate

Obfuscate a string to prevent spam-bots from sniffing it:

$value = 'Test';

echo HTML::obfuscate($value);

Output:

&#x54;&#x65#x65;s&#x74;