Producing collapsible field sets with theme functions 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
    drupal_add_js('misc/collapse.js');

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


    return $to_return;


}


My question, is there a better way to wrap this in a complete theme function? theme_fieldset and ctools_collapsible_theme(&amp;$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:
https://api.drupal.org/api/drupal/includes!form.inc/function/theme_fieldset/6

You can see an exemple in core here:
https://api.drupal.org/api/drupal/modules!system!system.admin.inc/function/theme_system_modules/6

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


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