Alter views using pre alter function

Last modified: June 18, 2009 - 19:37

Note: I have requested that this be added to Advanced Help in the Views module - see http://drupal.org/node/495626

To alter a view before it is rendered we can use hook_views_pre_render(&$view).
To view a list of views api refer to
http://views.doc.logrus.com/ .

To use this function we must add this function to the module file

<?php
function modulename_views_pre_render(&$view) {

}
?>

Just to make sure you only alter the view you want we will add a condition at the very top of this function to check if it is correct view.
Suppose your view name is "foobar". Then the code will lokk something like this.

<?php
function modulename_views_pre_render(&$view) {
  if(
$view->name == "foobar") {
     
//Add code to manipulate the view
 
}
}
?>

To view an example of how to alter a view footer check this out
http://drupal.org/node/422264#comment-1466510

 
 

Drupal is a registered trademark of Dries Buytaert.