oooh it was that theme_ function!

12 August 2008 mortendk
the poormans Theme developer drupal5 trick to figure out where "that" element was themed

Over the last 2 years one of my main headaches have been to figure out where a given part of the site were comming from - a lot of late nights of backtracking could have been avoided I just had read this übertrick from Todd Nienkerk (or i got the brain to figured it ;))

The Trick is super simple, i stumbled across it a couple of days ago while I was struggling with form theming, and thought that this was way to sweet to hold for my self. what this does is show you what theme functions is called - oooh foooorking yeah!

Go into you drupal sites root and go to includes/theme.inc and jump into the theme() function around line 170 chance the call_user_func_array to include a little comment with the theme functions:

#000000">#0000BB"><?php

   
#007700">return #DD0000">'<!-- begin ' #007700">. #0000BB">$functions#007700">[#0000BB">$function#007700">] . #DD0000">' -->' #007700">. #0000BB">call_user_func_array#007700">(#0000BB">$functions#007700">[#0000BB">$function#007700">], #0000BB">$args#007700">) . #DD0000">'<!-- end ' #007700">. #0000BB">$functions#007700">[#0000BB">$function#007700">] . #DD0000">' -->'#007700">;
#FF8000">//    return call_user_func_array($functions[$function], $args);
#0000BB">?>

Voila and now everytime Drupal5 is evil and not understand what your saying - jump into the source code and get the answer, and smack it into place - how goddamn cool is that!
offcourse this little hack will make the source look like crap, so what i do is to use it in my local MAMP setup, but not in a live site.

... why is it I just figured this out now - when im slowly working to convert to D6?

btw sorry for the crappy formatting of the code, my input filters are screwing with me - anyone got a hammer?

This should be core!

This should be core!

Tim Millwood 12 August, 2008 - 13:19

Core should not output debug

Core should not output debug info. This is good for development.
Have you tried the devel module Morten?

yaph 12 August, 2008 - 18:25

devel module with krumo is

devel module with krumo is like firebug, and coffee a themer must have ;)

mortendk 12 August, 2008 - 23:14

Soohit Dgeezus!

Best 2008 themer trick.

elv 12 August, 2008 - 13:36

Really nice hack (for

Really nice hack (for development site) - definitely no-no for production.

Drupal Theme Garden 12 August, 2008 - 16:56

one tiny issue...

It seems this also prints out :

<!-- begin phptemplate_page --><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

as the very first line, messing up IE's strict rendering mode. How can I get it to NOT print for this particular function? I'm not much of a coder.

Sammy Hendrick 12 August, 2008 - 19:02

well its not ment for the

well its not ment for the production enviroment - not on a live site.
This is just a hack to give a themer an idea of where the different elements of the site is coming from

mortendk 12 August, 2008 - 23:13

Very true, however if in a

Very true, however if in a staging site, if it's not rendering how it'll render in production, it kind of defeats the purpose. :-( Anyway, here's the bit of code I have to render things nicely for IE, and keep it out of quirks mode.

  if ($functions[$function]) {
  if ($functions[$function] == 'phptemplate_page') {
    return call_user_func_array($functions[$function], $args);
}
else{
return '<!-- begin ' . $functions[$function] . ' -->' . call_user_func_array($functions[$function], $args) . '<!-- end ' . $functions[$function] . ' -->';
    }
  }

This is a total life saver. :-)

Anonymous 13 August, 2008 - 14:22

devel_themer?

The devel_themer module does this with all kinds of fancy ajax magic in Drupal 6. However, thinking about it, with the theme registry you should be able to use the same trick devel_themer does to inject that sort of wrapping on every theme function except theme_page() without touching core.

I smell devel_themer patch coming... Who wants to do it? :-)

Larry Garfield 14 August, 2008 - 08:05

Update: Instructions added to Drupal.org

I've updated the Drupal.org page Using Theme Override Functions [in Drupal 5.x and earlier] to include these instructions.

Just so we're totally clear: This should never be done on a production site! This is a temporary hacking of core intended only for development environments.

Todd Nienkerk 1 December, 2008 - 19:29

jup but its soooo sweet a

jup but its soooo sweet a trick :)

mortendk 2 December, 2008 - 16:06

Pingback

[...] the inspiration to this version comes way back to the drupal5 days which i wrote about almost 2 years ago btw check out Larrys comment , so here @crell heres your patch. or rather i dont have a goddamn [...]
a Themer developers comments | morten.dk 18 November, 2010 - 10:43
The content of this field is kept private and will not be shown publicly.
@danigrrl yup true and she is the source for it - but okay she don't touch my espresso machine so i guess its okay (almost) 1 hour 59 min ago
3,252

DrupalCon Denver 2012 - I am a Speaker!

good Stüff

Mothership - a clean up the crap "theme"

Miro - a open atrium theme:
more info & comments

freya rocks

the progress for my premature daughter can be folllowed here:
Freya Rocks
sorry its in danish

the blög

Give some Love to the development of the mothership

Flattr this

User login

Recent comments

give some luv

drupal member ...

geek royale