If you create anything other than a very small site using Drupal you will end up using Views and CCK, two of the most important contributed modules in Drupal. Views allow users to dynamically create different presentation of tabular data from the database. However this also necessitates dynamic page titles for pages using views.
In Views 2 you can change the title of a page generated using views programmatically by the use of argument handling code. In Views 2 you can enter argument handling code by selecting 'PHP Code' as the validator type and then entering PHP code in the text area shown. Remember to not use <?php and ?> when you enter PHP code there.
Figuring out the logic to create the title should be easy for any PHP programmer. But figuring out how to set the title might not be so. You can set the title of the view as follows.
$view->display['display-identifier']->handler->handlers['argument']['argument-identifier']->options['title'] = 'Your custom page title';
In the above snippet display-identifier is the identifier for the display for which you are setting the title. You can figure that out by hovering your mouse over the displays and taking the id from the URI. Similarly the argument-identifier can be found out by hovering your mouse over the argument in the Arguments section.
$view->display['page_1']->handler->handlers['argument']['type']->options['title'] = 'Your custom page title';
In the above example page_1 and type are the ids.



Comments
Even better
Anonymous (not verified) wrote on October 31, 2011 - 07:05$view->display[$view->current_display]->handler->handlers['argument']['argument-identifier']->options['title'] = 'Your custom page title';
In the argument php
alexkb (not verified) wrote on September 30, 2011 - 12:47In the argument php validation code, setting $argument->options['title'] = "whatever"; is the only thing that worked for me (Drupal 6.20, Views 2.. Thanks anyway though.
- Alex
Thanks!
Anonymous (not verified) wrote on October 26, 2010 - 00:40Thanks, my problem is resolved!
great
fred (not verified) wrote on May 25, 2010 - 01:06Worked like a charm for me. Thx a lot
Also, I think there is a hook
insanity workout (not verified) wrote on January 24, 2010 - 08:04Also, I think there is a hook that can help with this but I can't remember the name.
This should take any code.
Josh (not verified) wrote on January 14, 2010 - 04:41In the title field of the Argument you should be able to just drop in something like "Gallery Category: %1"
Guess this is a way to take it farther.
Ignorance on my behalf?
Spoonful (not verified) wrote on November 24, 2009 - 00:50I can't work this out!
I get the code, I've dropped it into my views-view-table--Bender.tpl.php - not much action here
Looking at other obvious places to put the code.. 'Title' for the view I've created, consisting of only 1 page... Nope, this just spits the php into the title :-)
I'm using;
$view->display['page_1']->handler->handlers['argument']['nid']->options['title'] = 'Your custom page title';
-- 'nid' because my View takes in a single parameter - nid, and spits out the contents.
I'm sure it's obvious, but to me, seemingly not.
Thanks in advance,
pazzer
Use argument handling code
webmaster wrote on November 25, 2009 - 07:38Click on one of the arguments in the Views admin UI. This will pull up the argument settings form below. In the validator drop down select PHP code. Enter the above code in the textarea and then ensure that you return TRUE if you do not have any other validations to be done. If you already have a standard validation on your existing argument you should be able to use the global argument as argument 2 and then use the argument handling code for this second argument.
If you want professional help let us know and we can gladly take care of your problem.
Cheers
Anoop John
Team Zyxware
Review
Term papers (not verified) wrote on November 17, 2009 - 12:31Hi, thanks for the tips. That was a great help to me...
THANK YOU!!!!!
Aleks (not verified) wrote on October 13, 2009 - 00:57