How to know whether panels is used (inside template.php)

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Rubini's picture

Hi,

I want to hide the h1.title when panels is used to create an overview of sections. But in normal views there should be the h1.title.
Is there a way to get inside template.php the information if in this page panels is used?

Thank you for helping me.
Michael

Comments

Check out the technique used

jeff h's picture

Check out the technique used on http://drupal.org/node/232644. Basically:

  $current_panel = panels_page_get_current();
  if (!isset($current_panel->pid)) {
    // this page is not handled by panels
  }

Ugh. That node again. There

sdboyer's picture

Ugh. That node again.

There are several things wrong and/or misleading about the information presented in that node. This is one them.

That method will work fine - IFF you're using panel_pages. While probably the most common way in which panels is used right now, that function is not guaranteed to work in all circumstances. It will be useless if you're using panel nodes, or og_panels, for example, and as more and more modules come out that implement the Panels API on their own, that function will become less and less useful.

At the moment, there's no consistent way to know if Panels is being used from inside a given tpl.php file.

From keyboard of merlin (via IRC)

realityloop's picture

if (!panels_get_current_page_display()) {
  echo 'This isn't a panel';
}


if (panels_get_current_page_display()) {
  echo 'This is a panel';
}

@BrianGilbert_

Help make Drupal Melbourne meetups more awesome:
http://groups.drupal.org/node/204518

The best way to grow your local commununity is by participating in it!

Thanks!

nickrice's picture

Modifying jeff h's reply with this is exactly what I needed to sort out what I wanted to do - have a panels 3 page with panels content before the h1 header but without losing the title tag.

Basically what I did was:

  1. In page.tpl.php do a check for whether this is a panel page and don't print out the normal h1 heading if it is.

  2. Create a content pane view that just returns the node title within an h1 tag. The view has a single argument - node id taken from panels context.

  3. In panels, set the panel title to be the node title. This is automatically picked up and used for the tag but isn't output as a heading on the page because of 1.

  4. Insert the content pane view from 2 the top of the main content part of the panel.

Hey presto, can now put something above the h1 heading all within panels!

(Maybe there's a better way to do this - I'm still on the learning curve.)

Does not work if you have widths in your CSS

yowzer's picture

This does not work if you have widths in your CSS that vary depending on which regions have blocks in them. For example, in a Zen-based theme, the main content is X wide without any sidebars, X - sidebar width with 1 sidebar, and X - 2x sidebar width with 2 sidebars.

To correct this, I added this to my template_preprocess_page() implementation:

if (panels_get_current_page_display()) {
   $vars['sidebar_first'] = '';
   $vars['sidebar_second'] = '';
   $vars['layout'] = 'none';
}

if ($vars['layout'] == 'none') {
   if (! $index = array_search('no-sidebars', $vars['classes_array'])) {
      $vars['classes_array'][] = 'no-sidebars';
   }
}

This works for the Zen theme, but you might have to do something else for other themes. The next step to figure out would be to keep those regions from even being processed to cut down on processing time.

To resurrect this 4 year-old thread...

aendra's picture

Did anyone ever find a way to do this with a Panels Node? panels_get_current_page_display() doesn't seem to work with them... I'm needing a way to pass the name of the current layout on to theme suggestions. See: http://drupal.stackexchange.com/questions/39895/find-current-layout-name...

Thanks!

--
ændrew rininsland
news, photos, data, code.
aendrew.com :: @aendrew

Panels

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: