How do I use hook_views_pre_render in template.php in Drupal 7? I have some auto generated data from my articles stored in a view(my_amazing_view). I also have a custom field in articles where user can enter similar data. If user has entered the data, i want to show that data. Otherwise I want to show auto generated data.

To do this, I want to implement hook_views_pre_render in my template.php file and target that specific view. I tried naming the function as my_amazing_view_views_pre_render as well as mytheme_views_pre_render and targeting that view but I am unable to do so.

How do I use the pre_render hook in my theme?
The hook is run for every view, therefore you need to inspect the $view object (the parameter passed to the function).

Place the function in your theme's template.php.

Name it YOURTHEMENAME_views_pre_render (ie  replace 'hook' with your theme name). Then use $view object to target specific view name and display_id, as in $view->name and $view->display_id (from memory, I might be wrong, but you get the gist).

function MYTHEME_views_pre_render(&amp;$view){
  if ($view-&gt;name == 'VIEWNAME' &amp;&amp; $view-&gt;display_id == 'DISPLAY_ID') {
    // do what you want
  }
}


If you want to do this for many views, best do it like this to separate the views into their own functions:

function MYTHEME_views_pre_render(&amp;$view){ {
  // will run for all views
  $function = __FUNCTION__ . '_' . $view-&gt;name;
  if (function_exists($function)) {
    $function($view);
  }
}

function MYTHEME_views_pre_render_VIEWNAME(&amp;$view){
  // will only run for specific view, but for all of its displays.
}