• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
More help from the html helper

#1
[eluser]Unknown[/eluser]
I have been heavily modifying the html_helper.php to be exactly that a html helper. How do I submit these to possible include them in future CI releases?

Example

adding quick function like p(), div(), etc so you can quickly create theses elements in your view files.


My new functions so far
Code:
/**
* strong helper
*
* Generates <strong VAR="VAL">CONTENT</strong>
*
* @access public
* @param string
* @param mixed
* @return string
*/
if ( ! function_exists('strong'))
{
function strong($inner_html = '', $params = FALSE)
{
  return element($inner_html, $params, 'strong');
}
}

/**
* h1 helper
*
* Generates <h1 VAR="VAL">CONTENT</h1>
*
* @access public
* @param string
* @param mixed
* @return string
*/
if ( ! function_exists('h1'))
{
function h1($inner_html = '', $params = FALSE)
{
  return element($inner_html, $params, 'h1');
}
}

/**
* h2 helper
*
* Generates <h2 VAR="VAL">CONTENT</h2>
*
* @access public
* @param string
* @param mixed
* @return string
*/
if ( ! function_exists('h2'))
{
function h2($inner_html = '', $params = FALSE)
{
  return element($inner_html, $params, 'h2');
}
}

/**
* h3 helper
*
* Generates <h3 VAR="VAL">CONTENT</h3>
*
* @access public
* @param string
* @param mixed
* @return string
*/
if ( ! function_exists('h3'))
{
function h3($inner_html = '', $params = FALSE)
{
  return element($inner_html, $params, 'h3');
}
}

/**
* iframe helper
*
* Generates <element VAR="VAL">CONTENT</element>
*
* @access public
* @param mixed
* @return string
*/
if ( ! function_exists('iframe'))
{
function iframe($params)
{
  if ( ! is_array($params))
  {
   $params = array('src'=>$params);
  }
  
  $CI =& get_instance();
  
  return element(p($CI->lang->line('iframe_nosupport')), $params, 'iframe');
}
}

/**
* div helper
*
* Generates <div VAR="VAL">CONTENT</div>
*
* @access public
* @param string
* @param mixed
* @return string
*/
if ( ! function_exists('div'))
{
function div($inner_html = '', $params = FALSE)
{
  return element($inner_html, $params, 'div');
}
}

/**
* span helper
*
* Generates <span VAR="VAL">CONTENT</span>
*
* @access public
* @param string
* @param mixed
* @return string
*/
if ( ! function_exists('span'))
{
function span($inner_html = '', $params = NULL)
{
  return element($inner_html, $params, 'span');
}
}

/**
* a helper
*
* Generates <a  href="" VAR="VAL">CONTENT</a>
*
* @access public
* @param string
* @param mixed
* @return string
*/
if ( ! function_exists('a'))
{
function a($inner_html = '', $params = FALSE)
{
  if ( ! is_array($params))
  {
   $params = array('href'=>$params);
  }
  
  if ( ! isset($params['href']))
  {
   $params['href'] = '#';
  }
  
  return element($inner_html, $params, 'a');
}
}

/**
* P helper
*
* Generates <p VAR="VAL">CONTENT</p>
*
* @access public
* @param string
* @param mixed
* @return string
*/
if ( ! function_exists('p'))
{
function p($inner_html = '', $params = FALSE)
{
  return element($inner_html, $params, 'p');
}
}

/**
* element helper
*
* Generates <element VAR="VAL">CONTENT</element>
*
* @access public
* @param string
* @param mixed
* @param string
* @return string
*/
if ( ! function_exists('element'))
{
function element($inner_html = '', $params = FALSE,  $typ = 'div')
{
  // uses class if not array but set
  if (is_string($params))
  {
   $params = array('class'=>$params);
  }
  if ( ! is_array($params))
  {
   $params = array();
  }
  
  $html = "<$typ";
  foreach ($params as $k=>$v)
  {
   if ($k != 'html')
   {
    $html .= " $k=\"$v\"";
   }
  }
  $html .= ">$inner_html</$typ>";
  
  return $html;
}
}


This allows you to easily create these elements like so...

iframe
Code:
echo iframe('http://www.google.com');
produces
Code:
&lt;iframe src="http://www.google.com"&gt;
<p>Your browser does not support iframes.</p>
&lt;/iframe&gt;


p
Code:
echo p('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc at lorem non lorem vehicula convallis vel imperdiet metus. Maecenas ullamcorper.');
echo p('This is a quote', 'quote');
echo p();
produces
Code:
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc at lorem non lorem vehicula convallis vel imperdiet metus. Maecenas ullamcorper.</p>
<p class="quote">This is a quote</p>
<p></p>


or even easily create complex code easily
Code:
$html_content = NULL;

$html_content .= p(a(img('sample.jpg').br().'Text Here','http://www.domain.com'));

$params = array(
'id' => 'my_id',
);
echo div($html_content, $params);
produces
Code:
<div id="my_id">
<p>
<a href="http://www.domain.com">
<img src="sample.jpg" alt="" />
</a>
</div>


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.