I'm having a problem where a function call to a function in my template.php from a node is returning an undefined function error. And yet the function call works fine from a block. The only thing I can think of is that the code from the node body executes before anything else. Which would also explain why all that's displayed is the node body up until where my php code is. So am I right? Is there a way around this?

Comments

gpk’s picture

The why:

Well I guess that template.php hasn't been included by the time your node is parsed. I'm a bit surprised since the latter happens in http://api.drupal.org/api/function/menu_execute_active_handler/5 (see http://api.drupal.org/api/file/index.php/5/source), and the former via http://api.drupal.org/api/function/init_theme/5.

Ahh, I get it, I think the theme system is only initialised the first time http://api.drupal.org/api/function/theme/5 is called. Which is often/usually at the *bottom* of index.php.

The workaround:
Put init_theme() at the top of your node's PHP code.

gpk
----
www.alexoria.co.uk

attentat’s picture

The workaround works great. I'm just a little worried about the possible repercussions of initializing the theme early. Is this unfounded?

gpk’s picture

If already initialised then it does nothing if called again. If you included a theme('... call in your PHP page then the theme would be initialised at that point anyway.

gpk
----
www.alexoria.co.uk

attentat’s picture

Thanks!