I've noticed that when I set the title of the panel to 'none', the $head_title gets set to none too (which is right as this sets drupal_set_title). However, we often use title to 'none' in order to move the title elsewhere on the page - so would be nice to still have the $head_title to show in the browser tab bar. I've found a way to fix this via the template.php (so understand if this feature request gets closed), but if there is any easy way to get panels to pass data to the page.tpl.php which includes an original title or a 'head title' set by the user that would be absolutely fantastic. Alternatively if it can pass this data into the $variables array going into hook_preprocess_page, that would be nice too.

For the meantime, anyone needing to get the $head_title via the template.php, this is our solution.

function CHANGEME_preprocess(&$variables, $hook) {
  if ($hook == 'panels_pane' && empty($variables['title'])) {
    global $stored_panels_title;
    if (!$stored_panels_title) {
      //Panels has no title so make one available to template
      if ($variables['display']->context) {
	foreach($variables['display']->context as $context) {
	  if ($context->title) {
	    $stored_panels_title = check_plain($context->title);
	    break;
	  }
	}
      }
    }
  }
}

function CHANGEME_preprocess_page(&$variables, $hook) {
  if ($hook == 'page' && empty($variables['title'])) {
    global $stored_panels_title;
    $head_title = array(strip_tags($stored_panels_title), variable_get('site_name', 'Drupal'));
    $variables['head_title'] = implode(' | ', $head_title);
  }
}

Thanks v. much.

Comments

capellic’s picture

@christoph: Thank you very much for this code! Since I am using Drupal 7 (Zen), there is a CHANGEME_preprocess_html function. This is where the code you have in CHANGEME_preprocess_page goes.

I too would like to see this as a feature in Panels.

merlinofchaos’s picture

Status: Active » Closed (won't fix)

I don't think Panels is going to do this automatically. It's a choice of the theme, really, and doing this automatically would probably be wrong in other circumstances.

asimag’s picture

In above code you will also need to change $hook =='html' like below:

function CHANGEME_preprocess_html(&$variables, $hook) {
  if ($hook == ‘html' && empty($variables['title'])) {
    global $stored_panels_title;
    $head_title = array(strip_tags($stored_panels_title), variable_get('site_name', 'Drupal'));
    $variables['head_title'] = implode(' | ', $head_title);
  }
}