Use Views Argument as Page Title

While setting up a new website for MOLEC, Malaysian Online E-Resources Consortium Web Site, I wonder how on earth to set the Drupal page Title using Views Argument, instead of using the same Generic Title for each pages. I have created a number of nodes and each of these nodes is identified by Universities. A node may have one, two or more Universities. For example: EBSCOhost : Academic Search Premier may be subscribed by OUM,  UPM , USM and more. By using Views, I managed to create two seperate categories:

  1. List of Universities
  2. Database by Universities

1. List of Universities
The easiest one. Just create a Term view and select your taxonomies term. By magic of Drupal and View, the list will be displayed as intended.

2. Database by Universities
Not so tricky, but if you understand how arguments work – this is a no brainer. I created another Views Display, and this one is Node Type and add your argument in the argument box. For this case, the argument is the name of the universities. The arguments can be anything from term names or node titles or node type.

3. Modify the Links of the List of Universities
Since an argument will be used to display the databases of the universities, url output must be altered using the internal views function “Output this field as a link”. So that every links in the Universities List will be output according to its name. Eg: Open University Malaysia (OUM) –>> /molec/db/Open University Malaysia (OUM) Universiti Malaya (UM) –>> /molec/db/Universiti Malaya (UM) and so on Finaly the juice of this post – using the argument as the title. Two functions will be used to achieved this:

  1. views_get_current_view();
  2. drupal_set_title

In the Header Section of the Database View insert this code:

<?php
$view = views_get_current_view();
$arg = $view->args[0];

 if (empty($arg)) {
 drupal_set_title('MOLEC Resources List');
 }
 else {
 drupal_set_title($arg);
 }

?>

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.