Member of
Drupal Mauritius
Most of us have more than many functions in our template.php file. Hooks and preprocess function to make our site look as good as the designer did it. In many cases where a site requires advanced theming,the template.php file gets huge. To keep a structured and clean coding style consider using file includes. This way you can have codes in seperate php files loaded into template.php during execution.
This is a very similar approach to how Drupal core calls files from the "includes" folder.
Here's the code to include files :
<?php
require_once dirname(__FILE__).'/template.inc.php';
?>An example might be putting all your functions that are related to menu in one include file called menu.inc.php.
Performace Issue : Including files add small loading overheads so keep the number of include files reasonable.
Comments
Mike H
Thu, 12/08/2011 - 02:56
Permalink
I tried doing this with a
I tried doing this with a small php file with one function in it that I called from several phpo-input fields in one of my node types. The pages render correctly, but when I run Cron, I get a fatal error:
Fatal error: Call to undefined function my_function() in /home/xxx/xxx.xxx.com/modules/php/php.module(74) : eval()'d code on line 9
Any help would be greatly appreciated!
Add new comment