How to theme a table Drupal 7


  
  $items = array(
    array(
      'sender' => 'Lorem',
      'receiver' => 'Dolorem',
      'message' => 'This is a message',
      'amount' => 5,
    ),
    array(
      'sender' => 'Dolorem',
      'receiver' => 'Lorem',
      'message' => 'This is the reply',
      'amount' => 7,
    ),
  );
  
  $header = array(t('From'), t('To'), t('Message'), t('Amount'));
  $rows = array();
  foreach($items as $item) {
    $rows[] = array(
      $item['sender'],
      $item['receiver'],
      $item['message'],
      $item['amount'],
    );
  }
  
  return theme('table', array('header' => $header, 'rows' => $rows));

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.