Displaying a Table

Continuing the example from the previous page, you'll recall we ended up with a table that looked like this:

Name Age
Bob 23
Sue 21

That table would be displayed by calling the function tapir_get_table() and passing the table's ID, my_test_table, as the first argument like so:

<?php
print tapir_get_table('my_test_table', $null);
?>

(The second argument, $null, is passed to satisfy the second argment described below.)

The full function definition is as follows:

<?php
function tapir_get_table($table_id, &$arg, $theme_func = 'theme_table') {
  ...
  return
$output;
}
?>

The second argument is for optional parameters you need to pass to the table building function. For more than one parameter, it is recommended you simply use an array. This is extremely useful, as it's the only way to theme a form using TAPIr. You would use the following syntax in a theme_form() function to achieve this:

<?php
function theme_tapir_form_table_form($form) {
  return
tapir_get_table('my_form_table', &$form);
}
?>

This passes the form array by reference, so you can use drupal_render to render the form elements in the table cells. For more information, see the form rendering example in the Learn by Example section.

The output is by default themed by Drupal's function theme_table(), but you may specify an alternate function if you wish by passing its name as a string for the third argument. This custom function must accept the same arguments accept by theme_table and return its output as HTML in a string variable.