I'm trying to pass a variable to an user template, here is my code:
function template-name_preprocess_user(&$variables) {
$variables['foo'] = 'foo';
}
It doesn't work. I tried adding these line in the core User module preprocess and it works!
Template hooks like template_preprocess_user()
are implemented by custom module/theme by replacing template
with [MODULE_NAME/THEME_NAME]
. So, for example, if your theme short name is bartik, then the function name will be bartik_preprocess_user()
which will be implemented in the bartik.theme file.
function [MODULE/THEME_NAME]_preprocess_user(&$variables) {
$variables['foo'] = 'foo';
}
template-name_preprocess_user()
? Drupal doesn't use a name like that for template hooks. It usestemplate_preprocess_user()
,THEMENAME_preprocess_user()
, orMODULENAME_preprocess_user()
.