Html Class
The html class is an html wrapper for nearly all html tags.
Doctypes
We have included a configuration file located at fuel/core/config/doctypes.php which has all the doctypes.
h($content = '', $num = 1, $attr = false)
The h method returns an html heading tag. As you might be aware off the html heading tags come in 6 variations from h1 to h6.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$content |
required |
Content to be found between the heading tags. |
$num |
1 |
Designated number of the heading tag, if no value is supplied, will default to 1. |
$attr |
false |
Array of attributes to be applied to the heading tag. Content to be found between the heading tags. |
|
Returns |
String containing the correctly formated heading tags with its content(and attributes if supplied). |
Example |
//returns <h1>Example</h1>
echo Html::h('Example');
//returns <h2 id="h2" class="sample" style="color:red;">Some other example</h2>
echo Html::h('Some other example', '2', array('id' => 'h2', 'class' => 'sample', 'style' => 'color:red'));
//returns <h3 id="sample" class="sample" style="color:blue;">Variable!</h3>
$attributes = array('id' => 'sample', 'class' => 'sample', 'style' => 'color:blue');
echo Html::h('Variable!', '3', $attributes);
|
anchor($href, $text, $attributes = array())
The anchor method returns an html anchor tag.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$href |
required |
Target url |
$text |
required |
Anchor value |
$attributes |
false |
Array of attributes to be applied to the anchor tag. |
|
Returns |
String containing the correctly formated anchor tag (and attributes if supplied). |
Example |
//returns <a href="http://www.domain.com/example">Example</a>
echo Html::anchor('example', 'Example');
//returns <a href="http://www.otherdomain.com/example">Example</a>
echo Html::anchor('http://www.otherdomain.com/example', 'Example');
//returns <a href="http://www.domain.com/example" id="a1" class="sample" style="color:red;">Example</a>
echo Html::anchor('example', 'Example', array('id' => 'a1', 'class' => 'sample', 'style' => 'color:red'));
|
mail_to($email, $text, $subject = null, $attr = array())
The mail_to method returns an html anchor tag with mailto as target.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$email |
required |
Email address |
$text |
required |
Anchor value |
$subject |
null |
Anchor value |
$attr |
empty |
Array of attributes to be applied to the anchor tag. |
|
Returns |
String containing the correctly formated anchor tag (and attributes if supplied). |
Example |
//returns <a href="mailto:name@domain.com">Name</a>
echo Html::mail_to('name@domain.com', 'Name');
//returns <a href="mailto:name@domain.com?subject=Something">Name</a>
echo Html::mail_to('name@domain.com', 'Name', 'Something');
//returns <a href="mailto:name@domain.com" id="a2" class="sample" style="color:red;">Name</a>
echo Html:::mail_to('name@domain.com', 'Name', null, array('id' => 'a2', 'class' => 'sample', 'style' => 'color:red'));
|
mail_to_safe($email, $text, $subject = null, $attr = array())
The mail_to_safe method returns javascript code that produces an html anchor tag with mailto as target.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$email |
required |
Email address |
$text |
required |
Anchor value |
$subject |
null |
Anchor value |
$attr |
empty |
Array of attributes to be applied to the anchor tag. |
|
Returns |
String containing the correctly formated anchor tag (and attributes if supplied). |
Example |
//returns
//<script type="text/javascript">
// var user = "name";
// var at = "@";
// var server = "domain.com";
// document.write('<a href="' + 'mail' + 'to:' + user + at + server + '">Name</a>');
//</script>
echo Html::mail_to_safe('name@domain.com', 'Name');
|
br($num = 1, $attr = false)
The br method returns an html break tag.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$num |
1 |
Number of times the break tag should be outputted. If no value is given will default to 1. |
$attr |
false |
Array of attributes to be applied to the break tag. |
|
Returns |
String containing the correctly formated break tags with its attributes if supplied. |
Example |
//returns <br />
echo Html::br();
//returns <br id="example" class="sample" style="color:red;" /><br id="h2" class="sample" style="color:red;" />
echo Html::br('2', array('id' => 'example', 'class' => 'sample', 'style' => 'color:red'));
|
hr($attr = false)
The hr method returns an html ruler tag.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$attr |
false |
Array of attributes to be applied to the ruler tag. |
|
Returns |
String containing the correctly formated ruler tag with its attributes if supplied. |
Example |
//returns <hr />
echo Html::hr();
//returns <hr id="example" class="sample" style="color:red;" />
echo Html::hr(array('id' => 'example', 'class' => 'sample', 'style' => 'color:red'));
|
title($content = '')
The title method returns an html title tag.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$content |
required |
Content to be found between the title tags. |
|
Returns |
String containing the correctly formated title tag with its content. |
Example |
//returns <title>Some Title!</title>
echo Html::title('Some title!');
//returns <title></title>
echo Html::title('');
|
nbs($num = 1)
The nbs method returns ascii code for non-breaking whitespaces.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$num |
1 |
Number of non-breaking spaces to be outputted. |
|
Returns |
String containing the correctly formated ascii code for non-breaking whitespaces. |
Example |
//returns
echo Html::nbs();
//returns
echo Html::nbs(2);
|
img($src, $attr = array())
The img method returns an image tag.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$src |
required |
Path to image. |
$attr |
array() |
Attributes array. If no alt attribute is supplied, the alt attribute defaults to the filename. |
|
Returns |
String containing the correctly formated image tag. |
Example |
//returns <img src="http://example.com/path/to/image.png" alt="image.png" />
echo Html::img('path/to/image.png');
//returns <img src="http://example.com/path/to/image.png" alt="Alt Message" class="myclass" />
echo Html::img('path/to/image.png', array("alt" => "Alt Message", class => "myclass"));
|
meta($name, $content = '', $type = 'name')
The meta method returns meta tag or tags if multi-level array is supplied.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$name |
required |
Can be array containing single or multiple meta parameters or can be name/http-equiv value. |
$content |
required |
If no array is supplied on the $name parameter, $content equals to the meta attribute content's value. |
$type |
'name' |
If no value is supplied will default to name. Can be name or http-equiv. |
|
Returns |
String containing the correctly formated meta tags. |
Example |
//returns <meta name="description" content="Meta Example!" />
echo Html::meta('description', 'Meta Example!');
//returns <meta name="robots" content="no-cache" />
echo Html::meta('robots', 'no-cache');
$meta = array(
array('name' => 'robots', 'content' => 'no-cache'),
array('name' => 'description', 'content' => 'Meta Example'),
array('name' => 'keywords', 'content' => 'fuel, rocks'),
);
//returns <meta name="robots" content="no-cache" />
//returns <meta name="description" content="Meta Example!" />
//returns <meta name="keywords" content="fuel, rocks" />
echo Html::meta($meta);
|
doctype($type = 'xhtml1-trans')
The doctype method returns a correctly formated doctype tag.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$type |
'xhtml1-trans' |
Type of html doctype tag to be outputted. Accepted Values: xhtml11, xhtml1-strict, xhtml1-trans, xhtml1-frame, html5, html4-strict, html4-trans, html4-frame |
|
Returns |
String containing the correctly formated doctype tag. |
Example |
//returns the XHTML1 Transitional doctype tag.
echo Html::doctype();
//returns <!DOCTYPE html>
echo Html::doctype('html5');
|
header($content, $attr = false)
The header method returns a div tag with the id of header. When used along with the Html::doctype('html5') method will default to a header tag.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$content |
required |
Content to be found between the tags. |
$attr |
array() |
Array of attributes to be applied to the tag. |
|
Returns |
String containing the correctly formated header or div tag. |
Example |
//if html5 is set returns <header>Oh Yeah baby.</header>
echo Html::header('Oh Yeah baby');
//without html5 returns <div id="header">Oh Yeah baby.</div>
echo Html::header('Oh Yeah baby');
|
audio($src, $attr = false)
The audio method requires you to set html5 as the doctype in order to be used.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$src |
required |
Location of the source file or array containing multiple locations. |
$attr |
false |
Array of attributes to be applied to the audio tag. |
|
Returns |
String containing the correctly formated audio tag with its sources. |
Example |
//returns <audio><source src="../sounds/beep.mp3" /></audio>
echo Html::audio('../sounds/beep.mp3');
//returns <audio><source src="../sounds/beep.mp3" /><source src="../sounds/frog.mp4" /></audio>
echo Html::audio(array('../sounds/beep.mp3','../sounds/frog.mp4'));
|
ul($list, $style = false)
The ul method returns correctly formated single or multi-level unordered list.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$list |
required |
Array containing single or multi-level items to be outputted as list items. |
$style |
false |
Array of attributes to be applied to the ul tag. |
|
Returns |
String containing the correctly formated list. |
Example |
/* returns
<ul id="todo" class="pending">
<li>red</li>
<li>blue</li>
<li>green</li>
<li>yellow</li>
</ul>
*/
$items = array('red', 'blue', 'green', 'yellow');
$attr = array('id' => 'todo','class' => 'pending');
echo Html::ul($items, $attr);
/* returns
<ul class="order">
<li>colors
<ul>
<li>blue</li>
<li>red</li>
<li>green</li>
</ul>
</li>
<li>sky</li>
<li>tools
<ul>
<li>screwdriver</li>
<li>hammer</li>
</ul>
</li>
</ul>
*/
$items = array(
'colors' => array('blue', 'red', 'green'),
'sky',
'tools' => array('screw driver','hammer')
);
$attr = array('class' => 'order');
echo Html::ul($items, $attr);
|
ol($list, $style = false)
The ol method returns correctly formated single or multi-level ordered list.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$list |
required |
Array containing single or multi-level items to be outputed as list items. |
$style |
false |
(Optional) Array of attributes to be applied to the ol tag. |
|
Returns |
String containing the correctly formated list. |
Example |
/* returns
<ol id="todo" class="pending">
<li>red</li>
<li>blue</li>
<li>green</li>
<li>yellow</li>
</ol>
*/
$items = array('red', 'blue', 'green', 'yellow');
$attr = array('id' => 'todo','class' => 'pending');
echo Html::ol($items, $attr);
/* returns
<ol class="order">
<li>colors
<ol>
<li>blue</li>
<li>red</li>
<li>green</li>
</ol>
</li>
<li>sky</li>
<li>tools
<ol>
<li>screwdriver</li>
<li>hammer</li>
</ol>
</li>
</ol>
*/
$items = array(
'colors' => array('blue', 'red', 'green'),
'sky',
'tools' => array('screw driver','hammer'));
$attr = array('class' => 'order');
echo Html::ol($items, $attr);
|