I need to detect whether the current page is a View, and just can't find any variables or functions which i can use in my template.php or page.tpl.php.
For example, i need to append a class or id ("views vtype-currentview") to $body_classes in my Zen template. Classes like this are available in the divs enclosing the view content, but i need them at a higher level too.

Comments

sovietfunk’s picture

OK, hacked it myself. I made a simple function which i call in template.php and feed to the body_classes array if it returns a value. So now I have an additional class of .views-VIEWNAME to customize layouts and backgrounds with. I have only tested it with clean-urls and properly set paths. But I still can't believe that there isn't a function somewhere in views.module that does this. The global $current_view called in page.tpl.php only returns my calendar block view. Ah, well.

Here's the function:

function detect_views() {
  $allviews = array_flip(views_get_all_urls());
  if ($current = $allviews[arg(0)]) {
  	return $current;
  } else {
  	return FALSE;
  }
}
robertgarrigos’s picture

This is working with dirty urls also. Thanks for this.

---
Robert Garrigos
Professional site: robert.garrigos.cat
Catalan Drupal Users Group: drupal.cat

druvision’s picture

Works great for me

rooby’s picture