I am creating a module which accesses an old database, so I need to do some custom coding. I only need it for viewing data: https://github.com/vih/vih.dk-features/blob/master/vih_course_short/vih_...

I wanted to avoid having to write HTML code directly in the callback functions. How do I use a template (for instance a template with a table for the list)?

Comments

gbrands’s picture

If all you want to do is output your data from the old database to a table then you can use the theme function.

Example (assuming drupal v4.7-6)
theme_table($header, $rows, $attributes = array(), $caption = NULL)

More info can be found here:
http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_table/6

Hopefully this helps. If you have any questions, feel free to ask.

lsolesen’s picture

I am using Drupal 7, but looked at http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_table/7 instead. It seems allright. However, I need to figure out how to link the rows to a view for the single items. I guess the easier solution is just to do it directly in the method?

gbrands’s picture

In your module it looks like you either want to display a list of courses if an ID is not given, or if an ID is provided, show the data related to that ID. Is this correct?

So you could theme the table like so (d7 this time ; ) )

$table = array();
$table['header'] = array('ID','Course');

$result = db_query("SELECT navn FROM {kortkursus} WHERE dato_slut > :date", array(':date' => date('2009-m-d')), array('target' => 'vih'));

foreach ($result as $course) {
$table['rows'][] = array($course->id,l($course->navn,'kortekurser/'.$course->id));
}
theme_table($table);

Now each of the table rows has a link to click on to see more information. Is this what you were looking for?