You are here

public static function HamlHelpers::list_of in Sassy 7

* Iterates an array and using the block to generate a <li> element for each * array element. * Examples:<br/> * = list_of(array('red', 'orange', ...., 'violet'), 'colour')<br/> * = colour<br/> * Produces:<br/> * <li>red</li><br/> * <li>orange</li><br/> * |<br/> * |<br/> * <li>violet></li><br/> * * = list_of(array('Fly Fishing' => 'JR Hartley', 'Lord of the Rings' => 'JRR Tolkien'), 'title', 'author')<br/> * %h3= title<br/> * %p= author<br/> * Produces:<br/> * <li><br/> * <h3>Fly Fishing</h3><br/> * <p>JR Hartley</p><br/> * </li><br/> * <li><br/> * <h3>Lord of the Rings</h3><br/> * <p>JRR Tolkien</p><br/> * </li><br/> * *

Parameters

string Haml block: * @param array items * @param string string in block to replace with item key or item value * @param string string in block to replace with item value * @return string list items.

File

phamlp/haml/HamlHelpers.php, line 138

Class

HamlHelpers
HamlHelpers class. Contains methods to make it easier to do various tasks.

Code

public static function list_of($block, $items, $key, $value = null) {
  $output = '';
  foreach ($items as $_key => $_value) {
    $output .= '<li>' . strtr($block, empty($value) ? array(
      $key => $_value,
    ) : array(
      $key => $_key,
      $value => $_value,
    )) . '</li>';
  }

  // foreach
  return $output;
}