Overriding a view with views_pre_render. How to be more specific? I have a view which has a page display and a block display. I'm trying to write some custom code that takes one of the fields from the block and uses it to amend the title of the page. So far, here's my code:

function custommodule_views_pre_render(&amp;$view) {
  if ($view-&gt;name == 'topic_page') {
    $title = $view-&gt;result[0]-&gt;node_title;
    drupal_set_title($title);
  }


I managed to pinpoint the field I need by looking through the returned views result array. The problem is that there are multiple results arrays returned - one for each display, so there's two $view->result[0] in this view. The code above only happens to work for me because the one for the block is returned after the one for the page.

So in the interests of making sure the code doesn't break should another display be added to the view, and therefore having that display's result[0]->node_title become the one that overrides the page title, how do I increase the accuracy here? How do I pinpoint my block display?

(I realise there are plenty of contrib modules that can do this for me, but I'd really like to do this with custom code as something of a learning exercise.)
You should be able to put in logic like

if ($view-&gt;name == 'topic_page' &amp;&amp; $view-&gt;current_display == 'MACHINENAMEOFBLOCKDISPLAY') {
  // do whatever you want whenever Views is crafting up this view and display
}


which will further filter to a specific View as well as display.