1

I am looking to add a class to a table that I am creating.

I have the code:

$build['table'] = array(
  '#theme' => 'table',
  '#header' => $header,
  '#rows' => $rows,
);

I want to add a class to this table. I don't have any templates for the view of this table, so I don't really want to have to create a tpl.php for it, but I will if I have too.

3

Here is description of all parameters that you can pass to theme_table() function http://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7

To add classes for table tag use this code:

$build['table'] = array(
  '#theme' => 'table',
  '#header' => $header,
  '#rows' => $rows,
  '#attributes' => array (
    'class' => array('class name goes here'),
  ),
);
  • You're my knight in shining armour. – Jimmy Pitts Jul 27 '12 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.