Welcome Guest, Not a member yet? Register   Sign In
A different heading()
#1

[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 Smile

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;
    }
}


Messages In This Thread
A different heading() - by El Forum - 04-24-2009, 09:09 PM
A different heading() - by El Forum - 04-24-2009, 09:50 PM
A different heading() - by El Forum - 04-24-2009, 10:31 PM
A different heading() - by El Forum - 04-25-2009, 03:13 AM
A different heading() - by El Forum - 04-25-2009, 03:36 AM
A different heading() - by El Forum - 04-25-2009, 03:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB