[eluser]superwad[/eluser]
Hello,
I'm new to CI, and eager to learn. I'm building my first site in CI and I came across an instance where a default helper function didn't do what I wanted, so I made a slight change and thought I'd share it with the rest of you.
It's a simple modification of the heading function that takes an optional third parameter as an array that allows attributes to be passed, such as id, class, or whatever. I needed it for my site, and thought somebody else might benefit
Here you go.
Code:
/**
* Heading
*
* Generates an HTML heading tag. First param is the data.
* Second param is the size of the heading tag.
* Third param is an array of attributes.
*
* @access public
* @param string
* @param integer
* @param array
* @return string
*/
if ( ! function_exists('heading'))
{
function heading($data = '', $h = '1', $attributes=null)
{
$out = "<h".$h;
if (is_array($attributes)) {
foreach ($attributes as $k=>$v) {
$out .= " ".$k."=\"".$v."\"";
}
}
$out .= ">".$data."</h".$h.">";
return $out;
}
}