Welcome Guest, Not a member yet? Register   Sign In
html helper heading() - No class/id args accepted? Do I have to extend?
#1

[eluser]stormbytes[/eluser]
Trying to use the header() helper function (html helper) to generate a heading, it doesn't seem to accept any arguments beyond text string & heading level. Either I'm overlooking something (entirely possible) or this has got to be an oversight. If so, would I have to extend the helper function to provide for id/class? How would I go about that?
#2

[eluser]wiredesignz[/eluser]
The heading helper only has the two parameters that you describe. You will need to extend it.

Create MY_html_helper.php in application helpers add the new functionality there.
#3

[eluser]stormbytes[/eluser]
[quote author="wiredesignz" date="1286176997"]The heading helper only has the two parameters that you describe. You will need to extend it.[/quote]

Is the procedure for extending helpers in the UG? What's a good start?
#4

[eluser]wiredesignz[/eluser]
Inside the application/helpers/MY_html_helper.php I have added and modified the original code like so:
Code:
function heading($data = '', $h = '1', $attribs = '')
{
    return "<h".$h." ".$attribs.">".$data."</h".$h.">";
}
#5

[eluser]stormbytes[/eluser]
[quote author="wiredesignz" date="1286177109"]No real names in here please.[/quote]

Fixed - sorry about that
#6

[eluser]wiredesignz[/eluser]
Yeah you don't need to quote me when you are the very next post buddy.

I have edited my previous post to provide an example for you.

Usage would be something like:
Code:
echo heading('My Heading;, 2, 'class="some_class" id="some_id"');

Attributes only needs to be a string. Wink
#7

[eluser]stormbytes[/eluser]
Oki doke -

Will catch on to the etiquette soon enough.

Thanks for the example. I'll look it over.

Question that pops out - Does this override the normal 'heading()' helper function?

Actually.. I can probably RTFM on that on..
#8

[eluser]stormbytes[/eluser]
Well that does simplify it -

I'll still study the previous example, just for kicks.

Thanks!
#9

[eluser]stormbytes[/eluser]
I cleaned it up a bit, validated input, and added conditional spaces to make the finished tag look a bit cleaner.

With a custom Textmate command (bundles) this rocks Smile


Code:
// Function modified to accept tag attributes!

function heading( $data = 'Heading Text', $h = '1', $attribs = '' ) {
  
  
  $data = ( !strlen( $data ) == 0 ) ? $data : "Heading Text";
  
  $attribs = ( !strlen( $attribs ) == 0 ) ? " " . $attribs . " " : "";
  
  $heading = "<h" . $h . $attribs . ">" . $data . "</h" . $h . ">";
  
  return $heading;
}


Textmate Bundle Command

Code:
heading('${1:heading-text}', '${2:1}', '${3: ${4:id="${5:css-id}" }${6:class="${7:css-class}"}}');${0}

Anyone using Textmate (who has extended the 'heading()' html helper as described in this thread) can easily apply the code above to create a new textmate (bundle) command. I simply duplicated the existing 'heading' command (CodeIgniter 1.72 bundle) and applied the code above to the body of the command. Add a tab-trigger of 'heading' and this will allow you to individually tab through each of the elements of the heading tag/function.




Theme © iAndrew 2016 - Forum software by © MyBB