In an older Drupal 6 instance, I'm updating a module to produce a collapsible fieldset with the following:

function my_module_function($table_collections) {
    // include JavaScript for collapse functionality

    foreach($table_collections as $table) {
            $to_return .= '<fieldset class="collapsible collapsed">';
            $to_return .= '<legend><span><a href="#">' . $title . '</a></span></legend><div>' ;
            $to_return .= theme_table(array_keys($table[0]), $table);
            $to_return .= '</div></fieldset>';

    return $to_return;


My question, is there a better way to wrap this in a complete theme function? theme_fieldset and ctools_collapsible_theme(&$items) appears to be for forms. Is there a more standard or better approach than what I have above?


You can call theme_fieldset() directly, even if it's not for a form, as long as you structure the $element correctly:

You can see an exemple in core here:

$fieldset = array(
  '#title' => t($package),
  '#collapsible' => TRUE,
  '#collapsed' => ($package == 'Core - required'),
  '#value' => theme('table', $header, $rows, array('class' => 'package')),
$output .= theme('fieldset', $fieldset);

theme_fieldset() is also valid in Drupal 7, but it seems to have changed in Drupal 8.

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.