I'm having hard time theming text substitutions performed by my custom input filter. I'm using this theme hook:

function ppf_theme($existing, $type, $theme, $path) {
  return array(
    'ppf_link' => array(
      'template' => 'brand_product_link',
      'variables' => array(
        'title' => NULL,
        'nid' => NULL,
        'classes' => NULL,

accompanied by this code in my filter process callback:

return theme('ppf_link', array('nid' => $node_id, 'title' => $node_title, 'classes' =>  implode(' ', $classes)));

This basically works - i.e. I'm successfully printing out the nid and title variables in the brand_product_link.tpl.php file. I'm however unable to sneak in my custom classes in the classes variable. No matter what the classes array contains, Drupal will always render a single class ppf-link (which I assume is a default safe css class taken from my theme hook name). If I rename the variable to my_classes though - everything works ok.

Now, I'm not writing to get a fix for something that works, but to learn what I'm doing wrong when it does not. Is classes a protected variable? Should I use a template_preprocess_ppf_link function, if so - how should it look like?

  • What's the contents of $classes look like when you do this? Are you sure your filter process callback is getting executed before your theme hook? – beth Jul 30 '12 at 13:47
  • I have moved on now to the working state, where I'm appending my classes to classes_array, which works. The contents of $classes was exactly as built it (when I checked it by dpm()'ing the variable), it's just that they wouldn't render out. As per the sequence: I am definitely calling theme hook as the last statement of the process callback. – Artur Jul 30 '12 at 13:59
  • Your theme hook sets "classes" to NULL so if it's being called last, it would blank out any other values you put in before that. – beth Jul 30 '12 at 15:08
  • Yes, that's correct - but there is one invocation of the theme hook per one invocation of the tpl file, so NULLing the classes before that is more than desired. Each brand_product_link can have different classes, such as product-link-nid-#. – Artur Jul 30 '12 at 15:49

Your Answer

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

Browse other questions tagged or ask your own question.