Working with theme('table')

Events happening in the community are now at Drupal community events on www.drupal.org.
add1sun's picture

We need to think about how to handle instances of theme('table') in our work. There is no straight HTML to simply print in a tpl file for easy theming so what should we do with these guys? Below is an example tpl.php taken from user. Discuss.

user_admin_account.tpl.php

<?php

 
// Overview table:
 
$header = array(
 
theme('table_select_header_cell', array()),
  array(
'data' => t('Username'), 'field' => 'u.name'),
  array(
'data' => t('Status'), 'field' => 'u.status'),
 
t('Roles'),
  array(
'data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
  array(
'data' => t('Last access'), 'field' => 'u.access'),
 
t('Operations')
);
 
$output = drupal_render($form['options']);
  if (isset(
$form['name']) && is_array($form['name'])) {
    foreach (
element_children($form['name']) as $key) {
     
$rows[] = array(
     
drupal_render($form['accounts'][$key]),
     
drupal_render($form['name'][$key]),
     
drupal_render($form['status'][$key]),
     
drupal_render($form['roles'][$key]),
     
drupal_render($form['member_for'][$key]),
     
drupal_render($form['last_access'][$key]),
     
drupal_render($form['operations'][$key]),
);
    }
  }
  else  {
   
$rows[] = array(array('data' => t('No users available.'), 'colspan' => '7'));
  }
 
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array(), 'caption' => NULL, ));
  if (
$form['pager']['#value']) {
   
$output .= drupal_render($form['pager']);
  }
 
$output .= drupal_render($form);
 
//WARNING: make sure to return after the print, this is a return replacement
 
print   $output;
?>

Comments

How about leaving them

dvessel's picture

How about leaving them inside template.php but documenting what the expected results would be inside the .tpl.php file. And point to the .tpl.php file that generates theme_table().

It should just be documented very well. Not sure how else to work around this.

showing tabular form data

Gaurav Vashishtha's picture

Please provide me the code for viewing the data in tabular form in my custom module.
It should show in block.

Themer Pack Working Group

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: