Background: I'm writting a quick port to Panels tabs (here), and when building the tabs, I'd like to get the pane's title. Currently I'm doing this like this:

  foreach ($display->panels[$region_id] as $pane_id) {
    $pane = $display->content[$pane_id];
    $content = ctools_content_render($pane->type, $pane->subtype, $pane->configuration);
    $title = !empty($content->title) ? $content->title : t('Tab @delta', array('@delta' => $delta));
    // ...
    ++$delta;
  }

Is there a bette way, instead of reinvoking ctools_content_render(), where I can get the pane's title before it's rendered?

Comments

merlinofchaos’s picture

Status: Active » Fixed

Hm. No, titles are set upon render, not before. There's no way to get a pane's title prior to render. Often its dynamic and based upon what's being rendered.

amitaibu’s picture

> There's no way to get a pane's title prior to render

Indeed, however in my example theme_panels_tabs_style_render_region() gets the pane _after_ being rendered. So the question is there some (static) cache of the $block variable the pane returned?

Maybe another option would be regex, so I can yank the .pane-title from the rendered pane

merlinofchaos’s picture

Hm. It doesn't look like this data is stored for you.

You could implement hook_panels_pane_content_alter() and store the data in a static?

amitaibu’s picture

> You could implement hook_panels_pane_content_alter() and store the data in a static?

Yap, that did the trick. Module now "yanks" the pane title and uses it as the tab's title. thanks!

merlinofchaos’s picture

I think the renderer object could easily store this information. Styles should now have access to the renderer object I believe, so it would be pretty easy to do. Right now it only stores the rendered panes, not the unrendered, but there are several styles that need both. And irght now only the pane style gets the unrendered pane. It would be a relatively easy thing to do, and not costly becuase the renderer is destroyed at the end of the rendering process anyway.

Perhaps should move the issue to Panels for that.

amitaibu’s picture

Title: How to get the pane's title. » Keep the un-rendered $pane object in the $display object
Project: Chaos Tool Suite (ctools) » Panels
Version: 7.x-1.x-dev » 7.x-3.x-dev
Category: support » feature
Status: Fixed » Active

> Right now it only stores the rendered panes, not the unrendered, but there are several styles that need both

Maybe this can be related to -- #1227952: Convert and encourage content-type plugins to return renderable array . Maybe we can keep just the unrendered content, and let theme functions work on that array. It would be really nice if hook_page_alter() would get as much renderable arrays from Panels as possible.

> Perhaps should move the issue to Panels for that.

Re-assign to correct project.

moonray’s picture

Would be nice to be able to alter panel pane content further down in the theme layer, rather than having to deal with a rendered piece of data.
For instance, once you're in hook_preprocess() where the $hook is 'page', there's no way to alter pane classes or anything else.

A renderable array instead of pre-rendered markup would facilitate that.