0

Views let people to add custom css class to a display. I'm looking to get this information and add to the body tag.

I try with this two functions and the dpm() function from devel:

views_get_view('name');
views_get_page_view();

But I'm not able to find the custom class that I add to the view.

Do you have any idea how to get this information?

1
  • If you found the answer, please write it as answer. Questions and answers needs to be separated, since this is a Q&A site.
    – apaderno
    Aug 17 '13 at 7:55
0

If you only need to get this information, you can use template_preprocess_views_view

/**
 * Preprocess the primary theme implementation for a view.
 */
function YOURTHEME_preprocess_views_view(&$vars) {
  $view = $vars['view'];
  switch ($view->name) {
    case 'your_view_name' :
      // print out the array with all options to see what you're dealing with
      drupal_set_message('<pre>' . print_r($view->display['display_name']->display_options, true) . '</pre>');
      break;
  }
}

But if you will need to override this custom class, you'll need to use hook_views_pre_render()

function YOURTHEME_views_pre_render(&$view) {

  switch ($view->name) {
    case 'name_of_your_view' :

      // override the view settings
      // for example: $view->field['fieldname']->options['label'] = 'Some label';

      break;
  }
}
3
  • Sorry jack-Pl, I don't explain fine, I want to add the new css class to the body html tag. So I need to load the view within the hook_preprocess_html(). Aug 11 '13 at 16:00
  • no problem, I'll edit this, but if you have the view object within hook_preprocess_html() and all information is there, so where is the issue?
    – Jack-PL
    Aug 11 '13 at 16:33
  • I don't realize about the information in hook_preprocess_html. I'm going to check it. Aug 12 '13 at 14:51

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.