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.
anchor($href, $text, $attributes = array(), $secure = null)
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. |
$secure |
null |
Set to false to force http, or to true to force https on the created URL |
|
Returns |
String containing the correctly formatted 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'));
//returns <a href="https://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'), true);
|
mail_to($email, $text, $subject = null, $attr = array())
The mail_to method returns an HTML anchor tag with mailto as the 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 formatted 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');
|
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 formatted 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"));
|
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');
|
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 formatted 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 a correctly formatted 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('screwdriver','hammer')
);
$attr = array('class' => 'order');
echo Html::ul($items, $attr);
|
ol($list, $style = false)
The ol method returns a correctly formatted single or multi-level ordered list.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$list |
required |
Array containing single or multi-level items to be outputted 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);
|
Procedural helpers
html_tag($tag, $attr = array(), $content = false)
The html_tag function generates an HTML tag based on the attributes provided..
Parameters |
Param |
Type |
Default |
Description |
$tag |
string |
required |
the value to search for |
$attr |
array |
array()
|
array of attributes |
$content |
string |
false
|
the content wrapped in the tag |
|
Returns |
string |
Example |
echo html_tag('a', array(
'href' => 'http://somedomain.com/',
'class' => 'my_class'
), 'Link title');
// <a href="http://somedomain.com/" class="my_class">Link title</a>
|
array_to_attr($attr)
The array_to_attr function generates an attributes string.
Parameters |
Param |
Type |
Default |
Description |
$attr |
array |
required |
an array of attributes |
|
Returns |
string |
Example |
echo array_to_attr(array(
'href' => 'http://somedomain.com/',
'class' => 'my_class'
));
// href="http://somedomain.com/" class="my_class"
|