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.
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 |
echo Html::anchor('example', 'Example');
echo Html::anchor('http://www.otherdomain.com/example', 'Example');
echo Html::anchor('example', 'Example', array('id' => 'a1', 'class' => 'sample', 'style' => 'color:red'));
echo Html::anchor('example', 'Example', array('id' => 'a1', 'class' => 'sample', 'style' => 'color:red'), true);
|
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 |
echo Html::mail_to('name@domain.com', 'Name');
echo Html::mail_to('name@domain.com', 'Name', 'Something');
echo Html:::mail_to('name@domain.com', 'Name', null, array('id' => 'a2', 'class' => 'sample', 'style' => 'color:red'));
|
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 |
echo Html::mail_to_safe('name@domain.com', 'Name');
|
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 |
echo Html::img('path/to/image.png');
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 |
echo Html::meta('description', 'Meta Example!');
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'),
);
echo Html::meta($meta);
|
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 |
echo Html::doctype();
echo Html::doctype('html5');
|
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 |
echo Html::audio('../sounds/beep.mp3');
echo Html::audio(array('../sounds/beep.mp3','../sounds/frog.mp4'));
|
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 |
$items = array('red', 'blue', 'green', 'yellow');
$attr = array('id' => 'todo','class' => 'pending');
echo Html::ul($items, $attr);
$items = array(
'colors' => array('blue', 'red', 'green'),
'sky',
'tools' => array('screwdriver','hammer')
);
$attr = array('class' => 'order');
echo Html::ul($items, $attr);
|
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 |
$items = array('red', 'blue', 'green', 'yellow');
$attr = array('id' => 'todo','class' => 'pending');
echo Html::ol($items, $attr);
$items = array(
'colors' => array('blue', 'red', 'green'),
'sky',
'tools' => array('screw driver','hammer'));
$attr = array('class' => 'order');
echo Html::ol($items, $attr);
|
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');
|
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'
));
|