Working with theme('table')
public
group: Themer Pack Working Group
add1sun - Thu, 2007-02-01 23:48
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;
?>

How about leaving them
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.