3

Two part question about Drupal 7, Panels 3, and Views 3.

I have a view that I have added to a content area in a panels page. Right now, the title from the display is being used as the pane title. I need to dynamically set the title of this from a module.

  1. When does Panels pull out the display title from the view?

  2. Where exactly does it pull it out from?

I cannot seem to override this from any view hook. For example,

function foo_views_pre_view (&$view, &$display_id, &$args)
{
    $view->display[$view->current_display]->display_options["title"] = "Foo";
}

doesn't seem to affect the pane title, though the value does propagate through all of the other view hooks.

I suspect I can create a workaround and use a custom block instead of the view directly, but I would rather not do that in this case.

Thanks.

2 Answers 2

5

I was hoping that someone would answer this, so I wouldn't have to answer my own question when I found the solution.

Credit goes to a co-worker (who doesn't really post here) who reminded me that you also need to update the handler:

function foo_views_pre_view (&$view, &$display_id, &$args)
{
  $view->display[$view->current_display]->display_options["title"] =
  $view->display[$view->current_display]->handler->options["title"] = "Foo";
}

When you do this, the title does propagate properly to the pane title.

1
  • In my case I had to change $view->display['default']->handler->options['title'] rather than the $view->current_display.
    – neuquen
    Jan 16, 2015 at 20:22
2

Drupal grabs the view title from the view itself when the view is rendered.

You can over ride this in the panels settings area, by manually setting it.

Revision:

Have you tried doing this with a preprocess function something like

function MYTHEME_preprocess_panels_pane(&$vars) {
 if ($vars['pane']->type == 'node_title') {
  $vars['template_files'][] = 'panels-pane-node-title';
 }
}
2
  • Thanks, but as my question states, I specifically need to set the title from within a module and not the UI.
    – mpdonadio
    Feb 28, 2012 at 18:14
  • The pane preprocess is less than ideal because at this point the $pane->content has rendered content, so which particular view/display was used is now gone.
    – mpdonadio
    Feb 28, 2012 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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