functions I put in my template.php are not available as functions from within nodes (using the php input format).
using drupal 4.6 with php 4.3, I had no problem doing so, but now I work with 4.7/php 5 and there seem to be something different.

Was there a change in the way template.php's functions are included in the overall script?

How come the functions are accesible to drupal in order to override theme functions, but are not available from within a node?
I'm used to use template.php not only to override functions, but also to store my own functions to be used on my site, and now - I'm left outside in the dark with no place to "host" my functions.

Help will be most appreciated!

Comments

heine’s picture

Make a custom module that contains all your functions. You can then safely call those from within nodes.
Simply create a [name].module file in the directory modules/[name] or sites/yoursite/modules/[name], fill it with the functions, and enable the module via the administration pages.

--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.

z.stolar’s picture

That's a very interesting idea.

I beleive however, that such a solution should be supported by the core. Since most of the sites have customed functions, not theme-related ones, such a solution should be standardized.

When I think about it: it even makes more sense to do it that way, than to include customed functions in template.php . The logic of Drupal is that functions are added with modules, and it maintains seperation between theming your site, and adding functionality to it.

So adding an empty core module, called myFunctions.module, might be a good idea, just to keep naming conventions. I'll create such module and see what people think about it.

By the way, can anyone explain the reason for not having the template.php functions included? is it something to do with that:

In PHP 3, functions must be defined before they are referenced. No such requirement exists since PHP 4. Except when a function is conditionally defined...

(source: http://php.net/manual/en/language.functions.php) ?

======================
Z.Stolar

heine’s picture

Functions do not need to be defined before calling them, but they have to be loaded. If you call a function residing in template.php before that file is included, you'll get the undefined function error.

Template.php is only included when the theme system is first initialized. Any calls to template.php functions before the first init will fail,

My opinion is that template.php should be used as intended: to override phptemplate behaviour.
--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.