By Woggers on
Could someone please provide a link or explain the difference between these two template.php overrides? When do you use one and when the other? Why will one work sometimes and the other will not?
Whats the stored differently between the $variables & $vars ?
Thanks in advance!
Comments
preprocess functions
I assume you are having some trouble with the docs: http://drupal.org/node/223430 ?
Back to your question...
hook_preprocess_page(&$variables)
There is no hook_preprocess_page() as such. In this example it is "page" that is the theme hook. Your "hook_" bit should be either 'template', a modulename, an enginename, or a themename depending on its scope.
eg with:
phptemplate_preprocess_page(&$vars)
This is the same "page" theme hook above but the actual example that would be used by the theme engine (phptemplate).
So if your module wanted to do some of its own preprocessing for the page templates you would implement a function called yourmodulename_preprocess_page(&$variables).
BTW: there is no difference between using $vars and $variables - that is just the local internal name of the array passed to the function. It has no bearing on what the array is called outside the function. I would recommend using $variables, but that is purely based on what the documentation examples use.
hook_preprocess_page(&$variab
hook_preprocess_page(&$variables) is the generic name
the theme system looks for the existence of:
themename_preprocess_page()
phptemplate_preprocess_page()
template_preprocess_page()
when it build the theme registry, if found, these function(s) are called when theme('page', ...) is called.
For the 'page' hook, there is a template_preprocess_page() in theme.inc the theme system will invoke. Theme can provide their own by defining themename_preprocess_page() or phptemplate_preprocess_page() in template.php in case the theme needs to define more variables.
Working example
As styro states, there is no difference between using $variables and $vars. For example, look at the breadcrumb preprocess function in Garland's template.php file:
function phptemplate_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
return '
';
}
}
You can change the argument '$breadcrumb', to read, say, '$hansel_and_gretel':
function phptemplate_breadcrumb($hansel_and_gretel) {
if (!empty($hansel_and_gretel)) {
return '
';
}
}
If you try it out yourself, it may be helpful to change the spacer from ' › ' to ' -- ' so you can confirm the change to your theme when you reload the page; make sure you display a node that calls the breadcrumb.