Hi There -

Was going through the exercises in Robert Douglass' book: _Building Online Communities With Drupal, phpBB, and WordPress_ and got to page 172, Exercise 5-3. This is a very cool little piece of code that, when inserted into theme.inc (in the includes directory) replacing the theme() function, inserts comments into the html of the code indentifying which themable function each piece of html is generated from. All you have to do is view source and you see what makes what on your page. Way nifty.

I couldn't get it to work and wrote to Robert Douglass, who kindly gave me updated code that works with Drupal 4.7.3.

It worked flawlessly the first time I tried it.

At his request, I'm posting it here:

/**
* Generate the themed representation of a Drupal object.
*
* All requests for themed functions must go through this function. It examines
* the request and routes it to the appropriate theme function. If the current
* theme does not implement the requested function, then the current theme
* engine is checked. If neither the engine nor theme implement the requested
* function, then the base theme function is called.
*
* For example, to retrieve the HTML that is output by theme_page($output), a
* module should call theme('page', $output).
*
* @param $function
*   The name of the theme function to call.
* @param ...
*   Additional arguments to pass along to the theme function.
* @return
*   An HTML string that generates the themed output.
*/
function theme() {
 $args = func_get_args();
 $function = array_shift($args);

 if ($func = theme_get_function($function)) {
   return "<!-- BEGIN: $func -->\n". call_user_func_array($func, $args). "\n<!--END: $func -->\n"; ;
 }
}

Comments

jaydunford’s picture

Cheers Capoeirista - That was just what I needed : )

[ edit: eh? - why can't I see my new signature in this comment ? ]

newbstah’s picture

All credit goes to Robert Douglass who replied right away with the correct code when I wrote to him. Awesome guy!