1

View Path: team/member/% Contextual Input: Numeric User ID, single variable

The purpose of my view is to 1) use Views Responsive Grid to layout the page appropriately, which I have done, and 2) leverage the power of views to include future content / fields / etc. After I finished building everything and themed it the way I wanted, I found that the page title was blank.

My question: Is there a way to override the page title before the HTML is processed for this Views path? Ideally, I would like the title to be: "[first name] [last name] | Site Name" The user's separated first and last names are available as fields.

I appreciate everyone's help with this! (view the bottom image in a new tab, it's pretty wide)

Page Title in Chrome

My Views settings for this page

1

It can be done by placing the following code in your theme's template.php file (please note that my fields were named field_last_name and field_first_name, and my view was a page display with the view name 'user_stuff' - so please adjust your accordingly - you can inspect your values by installing devel and uncommenting the dpm statement).

function MYTHEME_views_pre_render(&$view){
  //dpm($view);
  if ($view->name == 'user_stuff' && $view->current_display == "page" && $view->total_rows > 0) {
    $first_name = $view->result[0]->field_field_first_name[0]['rendered']['#markup'];
    $last_name = $view->result[0]->field_field_last_name[0]['rendered']['#markup'];
    $site_name = variable_get('site_name', 'My Site Name');
    $view->build_info['title'] = "$first_name $last_name | $site_name";
  }
}

There is also no need for the pager and you should rather set your view to display 1 item only. Also note that you are outputting the rendered markup (as opposed to the raw value) so there is no need to sanitise the values.

| improve this answer | |
  • You are a lifesaver. I had to add a CSS style to hide the hideous default node title Drupal places on top of the node, but otherwise it works perfectly. The pager wasn't really an issue because there can only be one result, but I am going to change it for OCD reasons :) +1 internets for you sir! – meinemitternacht Jan 11 '15 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.