Hi,

I'd like to know what was the way to detect if the current page is a panel page ?

For example, a simple test like if($node) tell me if the page a node or not.
I'd like to do the same in page.tpl.php for panels, to have a different class in this case for my div surrounding $content.

Thanks to all your work !

Comments

Pierre_G’s picture

Reading again my message, I'm realizing I'm not that clear and my english wasn't that good :)
I'll try to explain a bit clearlier.

In my blueprint theme (and in most themes I think), I've my pages displayed like this (I simplified) :

<div class="left"></div>
<div class="center">
  <h1>$title</h1>
  <div class="content-inner">
    $content
  </div>
</div>
<div class="right"></div>

Let's say my body have a black background, and my panels are blocks with white backgrounds, separated by a few pixels from each others.
If I want to theme this, I'm simply adding a white background to the .panel-pane div.

But for other pages which are not ruled by panels, the content will be on a black background, that's not what I want. I want the main content part of my website to be in a white block as well.
As panels are placed in the $content part of the page (see my html code above), if I'm setting a white background to the main content part, my white panels will be all surrounded by white, and not anymore separated by the black of the body background.
(you're still following?)

So I'm looking for a solution to achieve this, and the simpliest way, I think, is to detect if this is a panel page, and to set the main content background to 'none' in this case.

I hope I was clearer this time, sorry if I'm missing a simple way to theme something like this :)

h-man24’s picture

you can give every panel a css-id. with that you can use the CSS workflow by

for example

#block-id // define your background color for the block
{
background: #0000FF;
}

#panel-id #block-id  // overwrite your backgroundcolor of block with a new value
{
 background: #FF0000;
}

Try to use the FF-Plugin Webdeveloper to find out your needed classes or ids.

Stefan

merlinofchaos’s picture

Title: How to know if current page is a panel ? » Make a better way to detect if a Page Manager Page is in use.
Project: Panels » Chaos Tool Suite (ctools)
Version: 6.x-3.0 » 6.x-1.x-dev
Component: Panel pages » Code
Category: support » feature

I have this in a template.php which is a hacky method to detect this:

function assign_preprocess_page(&$vars) {
  $item = menu_get_item();
  if ($item['page_callback'] == 'page_manager_page_execute') {
    $vars['template_files'][] = 'page-panel';
  }
}

There needs to be a better way to detect this but it does not exist yet.

Pierre_G’s picture

Thanks a lot merlin, I'll give it a try when I'll have some time and give you a feedback about it.

ianchan’s picture

subscribe

merlinofchaos’s picture

Status: Active » Fixed

Ok, I introduced a new function: page_manager_get_current_page()

I tested it like this:

function assign_preprocess_page(&$vars) {
  $page = page_manager_get_current_page();
  if ($page) {
    $vars['template_files'][] = 'page-panel';
    $vars['template_files'][] = 'page-' . $page['name'];
  }
}

One thing to note: During preprocess_page() it's too late for dsm() or drupal_set_message() to work, so you're best off adding debug messages to $vars['content'].

merlinofchaos’s picture

Or maybe $vars['messages'].

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Pierre_G’s picture

Status: Closed (fixed) » Fixed

Thanks a lot, it works like a charm.

Added this in the class attribute of the main content div :
if(in_array('page-panel', $template_files)) print ' panel-page-wrap'; else print ' normal-page-wrap';
It's giving me two classe :
panel-page-wrap if I'm on a panel
normal-page-wrap if I'm on any other page

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

OpenChimp’s picture

I wanted to do something like this in D7. I had very simple requirements. I'm using panels and I wanted any panels page to use a different page tpl file than the pages which are not handled by panels.

Here's what I added to the THEMENAME_preprocess_page function in template.php:

  //  add a tpl file suggestion for panel pages
  if(module_exists('page_manager') && page_manager_get_current_page()) {
    $vars['theme_hook_suggestions'][] = 'page__panel';
  }

I then just created a file called page--panel.tpl.php in the same directory as my page.tpl.php file, cleared caches, and was good to go.