Search code examples
phpdrupal-7

Include file with functions in node.tpl.php and execute them on node content


First at all, I know that this isn't the correct way to do this in D7, but I need to do in this way.

I've included a file in node.tpl.php:

include DRUPAL_ROOT . '/sites/all/themes/mytheme/inc/node_functions.php';

In this included file I have a function which, afterwards I want to call from a node's content-body.

Currently, if I call the function from a node content, I get a WSOD. I also checked if within a node-content the function exists, with a PHP function:

function_exists('name_of_my_function')

but it returns FALSE, so the function no exists in this 'scope'.

In summary, I want a collection of helpful functions included/attached to a node, but I don't want to write the include/require statement everytime I'm creating a node. I only want to simple 'call' those functions. So, how can I do it?

Thanks in advance.


Solution

  • I finally wrote a custom module to reach my goal. As @Leonando Tan noticed me at DrupalAnswers, Someone can write a module with a custom functions (not related to a particular hook). I didn't know it, because I am newby developing drupal modules (In fact, this is my first module).

    However, in this case, was so easy to include my generalist functions in a module. Doing it in that way, these functions are available throught all the website, so I call/invoke them whenever and wherever I want.