1

If you have a theme function like theme_field() for instance. I know you can do something like this:

function THEMENAME_preprocess_field(&$varialbes) {
  dpm($variables);
}

and that will print out the all the variables (if you have Devel enabled). Then I see theme_hook_suggestions like this "field__field_date__featured_event". However, when I try to do this:

function THEMENAME_preprocess_field__field_date__featured_event(&$varialbes) {
  dpm($variables);
}

The above does not work at all. Why is this? Is it possible to use a preprocess function on a theme suggestion? or are theme suggestions just for theme overrides and not for preprocessing?

thanks!

0
2

You need to do this before you can do that...

/*
 * Implements hook_preprocess_field().
 */
function YOURTHEME_preprocess_field(&$vars) {
    if ($vars['SOME_FIELD']) {
        $function = 'YOURTHEME_preprocess_field__'.$vars['SOME_FIELD'];
        if (function_exists($function)) {
            $function($vars);
        }
    }
}
5
  • so there isn't a way to use the theme suggestions to automatically preprocess things? Then what's the point of them? thanks! Nov 7 '12 at 15:52
  • Think your getting confused with the conventions for templates. theme_hook_suggestions are suggestions templates, not hooks.
    – Alex Gill
    Nov 7 '12 at 15:59
  • 1
    @DavidBarratt Alex is right, they're for template files, not for preprocess functions. theme_hook_suggestions are added in a preprocess function, so for them to also affect other preprocess functions could easily introduce a nasty in-escapable loop
    – Clive
    Nov 7 '12 at 16:11
  • 1
    It's actually a bug drupal.org/node/939462 Nov 7 '12 at 18:36
  • @barraponto Thanks I haven't come across that one before, I just assumed it was like that by design
    – Clive
    Nov 7 '12 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.