2

Be kind to me, my forte is definitely NOT in the pre-process area... or hooks, etc. :-)

I'm using Omega 3.x in Drupal 7. I found a nice function that pulls the user's roles and prints each role as a class in the body. I'm trying to do the same by pulling taxonomy terms from a field "field_event_type" in a product I've got.

I already tried this: add css class to html element based on taxonomy?

... but it's not printing the class. I tried duplicating the logic from the "user role" part. Can anyone lend an assist? I'm trying to print the various taxonomy terms from the field "field_event_type". Much thanks in advance!!

function saleo_preprocess_html(&$vars) {
  $body_classes = array($vars['classes_array']);

  if ($vars['user']) {
    foreach($vars['user']->roles as $key => $role){
      $vars['attributes_array']['class'][] = 'role-' . drupal_html_class($role);
    }
  }

  if (!empty($vars['node'])) {
    $node = $vars['node'];
    if (!empty($node->field_event_type)) {  
      foreach($vars['node']->field_event_type as $key => $tags){
        $vars['attributes_array']['class'][] = 'tax-' . drupal_html_class($tags);
      }
    }
  } 
}
  • 2
    Install Devel module and make sure all elements you are working with exist for sure. You can do that by using dpm() function - e.g. dpm($vars) to see what exactly is there. – Aram Boyajyan Oct 11 '13 at 6:26

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.