Drupal: dynamic generated title of a view

iKnow-IT banner

  • You must have the PHP Filter module enabled (admin/build/modules).
  • In your page view (admin/build/views/edit/[your view name]) click on header under Basic Settings
  • Place the following in the text box that pops up:

<?php
  $view = views_get_current_view();
  // [0] is first arg, [1] is second etc.
  //My first argument is a Node:Nid argument to get the node id from the url.
  $node = node_load($view->args[0]);
  drupal_set_title('Node '. $node->title);
?> 

  • Expand the Input Format section and select PHP Code:
  • Click update and the title should now display properly!          

 

If you will dynamically filling the header with, a view exposed filter field from the view:

<?php
  $view = views_get_current_view();
  //dsm($view->exposed_input);
  drupal_set_title('Title: '. $view->exposed_input[City]);
?>