I've created a custom module that has a bunch of PHP functions whose main purpose is basically to output HTML. For example:
function showRecentActivity($tid, $recordStart, $count){
//do some db_select stuff to get an array of node IDs...
foreach($nids as $nid){
$node = node_load($nid);
//now that we've loaded the node, 100 lines of if, echo, etc. will follow in order to output the HTML to the page
}
Perhaps you can already see the problem. While echoing HTML is fine for small pieces of markup, constructing full pages with echo statements is horrible to code, maintain, and very bug-prone.
Obviously what is needed is a pre-defined template file, written in HTML with just small places for echoing the necessary PHP variables. Just like my theme's template files.
But I have no idea how to do this with my custom module.