On 7.3.0-rc1 I can set the title of a page using a PHP field with this little snippet: drupal_set_title($title = $row->title)
On 7.x-3.x-dev this doesn't work.
I'm not sure if this is a bug or if something has changed...
If things have changed can anyone tell me how we can achieve this?

Comments

dawehner’s picture

It's by design. If you want to change the title you should do it after generating the view, because views has to set it, too.

aristeides’s picture

Dereine I know you're really busy and I 'm always surprised to see you're the one answering almost all the issues here. But could you (or someone else) provide an alternative?

If you want to change the title you should do it after generating the view

does that mean I'd have to create a custom module just for this function?

views has to set it, too

Do you know if it's in the roadmap making the title fieldable? or perhaps make it accept tokens? It would solve problems we 've always adressed using the views_php module and writing snippets... but since this is now not doable we should have another way to do it.

dawehner’s picture

You should checkout the latest dev. Views has support for tokens in the title.

aristeides’s picture

Status: Active » Closed (fixed)

Wow, thanks... marking as closed.

kyle_mathews’s picture

For those still wanting to change their View title in code, this is what I figured out will work in the latest release.

I was using hook_views_pre_render() -- that doesn't work anymore.

But take your same code and switch to use hook_views_post_render and make it look something like:

/**                                                                                  
 * Implementation of hook_views_post_render().                                       
 **/                                                                                 
function YOUR_MODULE_views_post_render(&$view) {                                      
  if ($view->name == "YOUR_VIEW_NAME") { 
    // Do some work here.                                                               
    $view->build_info['title'] = $new_title;
  }                                                                                    
}
scotwith1t’s picture

NICE! Thanks.

hyperglide’s picture

I believe I am trying to accomplish the same thing as noted in this issues #1602058: How to set the Page Title In Views (PageTile 7.x-2.7 and Views 7.x-3.7).

is this the solution any way to do without custom code per view?

Ty

scotwith1t’s picture

dawehner mentioned above that the latest dev supports tokens for the title, but i haven't tried that out...otherwise, this is a pretty simple custom code to stick in a module...