Welcome Guest, Not a member yet? Register   Sign In
html helper: ul (Alternating row colors)
#4

[eluser]GrahamDj28[/eluser]
Hi,

There is a way you can do what you want to do.

Create a file in application/helpers/ and call it MY_html_helper.php
(if you have changed the file prefix in your config, then use what you have defined there instead of MY_)

Then copy the the following functions to that file:
You will find these functions in system/helpers/html_helper.php
Code:
if ( ! function_exists('ul'))
{
    function ul($list, $attributes = '')
    {
        return _list('ul', $list, $attributes);
    }
}

Code:
if ( ! function_exists('ol'))
{
    function ol($list, $attributes = '')
    {
        return _list('ol', $list, $attributes);
    }
}

Code:
if ( ! function_exists('_list'))
{
function _list($type = 'ul', $list, $attributes = '', $depth = 0)
{
  // If an array wasn't submitted there's nothing to do...
  if ( ! is_array($list))
  {
   return $list;
  }

  // Set the indentation based on the depth
  $out = str_repeat(" ", $depth);

  // Were any attributes submitted?  If so generate a string
  if (is_array($attributes))
  {
   $atts = '';
   foreach ($attributes as $key => $val)
   {
    $atts .= ' ' . $key . '="' . $val . '"';
   }
   $attributes = $atts;
  }
  elseif (is_string($attributes) AND strlen($attributes) > 0)
  {
   $attributes = ' '. $attributes;
  }

  // Write the opening list tag
  $out .= "<".$type.$attributes.">\n";

  // Cycle through the list elements.  If an array is
  // encountered we will recursively call _list()

  static $_last_list_item = '';
  foreach ($list as $key => $val)
  {
   $_last_list_item = $key;

   $out .= str_repeat(" ", $depth + 2);
   $out .= "<li>";

   if ( ! is_array($val))
   {
    $out .= $val;
   }
   else
   {
    $out .= $_last_list_item."\n";
    $out .= _list($type, $val, '', $depth + 4);
    $out .= str_repeat(" ", $depth + 2);
   }

   $out .= "</li>\n";
  }

  // Set the indentation for the closing tag
  $out .= str_repeat(" ", $depth);

  // Write the closing list tag
  $out .= "</".$type.">\n";

  return $out;
}
}

Update the last function to fit your needs. E.g. you can add a counter which is used to set the correct class on the <li>

And for the CSS given, instead of color, you can use background to set the background color. Color is used for the font coloring. Using background you also do not need to reset the text color with a span


Messages In This Thread
html helper: ul (Alternating row colors) - by El Forum - 05-01-2012, 11:00 AM
html helper: ul (Alternating row colors) - by El Forum - 05-01-2012, 11:55 AM
html helper: ul (Alternating row colors) - by El Forum - 05-01-2012, 12:06 PM
html helper: ul (Alternating row colors) - by El Forum - 05-01-2012, 01:57 PM
html helper: ul (Alternating row colors) - by El Forum - 05-01-2012, 03:17 PM
html helper: ul (Alternating row colors) - by El Forum - 05-26-2012, 01:11 PM
html helper: ul (Alternating row colors) - by El Forum - 05-26-2012, 02:01 PM
html helper: ul (Alternating row colors) - by El Forum - 05-26-2012, 05:07 PM
html helper: ul (Alternating row colors) - by El Forum - 05-27-2012, 06:36 PM
html helper: ul (Alternating row colors) - by El Forum - 05-27-2012, 09:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB