The problem
Pay attention to your first sentence:
I have created a theme that contains several functions.
The link that you have provided warns about what type of functions hold a template.php
in a theme.
There are two main types of functions in template.php: theme function
overrides and preprocess functions. The template system handles these
two types in very different ways.
Is legendary_views_field_compare_value() any of these cases? OK, we agree that the anwers is No. It's a custom function that you have written.
Why should not you put your custom functions in template.php
?
Because Drupal has a registry of implemented hooks and templates that have been overriden. The system only load the template.php
when match the hook in the registry. So, the template.php
is not always load.
The solution
First of all, you should keep separate the custom functions from the theme functions. You need to create a file called for example my_custom_functions.inc
, and insert all your custom functions in that file.
How do i load a file with custom functions that i need to call in my templates?
To keep separate the logic from the theme functions, i would stored the custom functions in a module. But, it is also possible store the functions in your theme. In both cases, you have to follow the next strategy.
It's really easy. Every time that a template is rendered, a preprocess function is fired by default to let other modules to act. So, it is always fired a preprocess (and process) function before the slideshow.tpl,php. In this moment, we will load the file with our custom functions.
Here an example:
/*
* Implements hook_preprocess_slideshow()
*
* The file will load before rendering slideshow.tpl.php
*/
function NAME_OF_YOUR_THEME_preprocess_slideshow(&$variables){
include_once 'my_custom_functions.inc';
}
Please, pay attention to the name of the template. In my simulation, i have changed the template called views-slideshow.tpl.php
. So, when you implements in hook_preprocess_HOOK(&$vars) , you need to change the hyphens. The result would be NAME_OF_YOUR_THEME_preprocess_views_slideshow(&$vars)
If you have to load the same file with custom functions in lots of templates, you could implement the general hook_preprocess($vars)
, that it is always fired. Here an example:
/*
* Implements hook_preprocess()
*
* The system always load the file
*/
function NAME_OF_YOUR_THEME_preprocess(&$variables){
include_once 'my_function.inc';
}
myfiles.inc
go in the theme directory. Also how do you a reference an Inc file in a .info file. I've looked at this tutorial about .info files, but it doesn't say how to add inc files in an info file. Thanks for any help you can offer.