Hi, I've tried to create a custom page theme for panels. I've tried creating a file called page-panels.tpl.php but it doesn't seem to work. Is there some other way?

Comments

OpenChimp’s picture

I'd also love to create a single page-_____.tpl.php file that modifies all panels pages on my site. My need is fairly simple, so perhaps there is a better way to do it.

I have an existing site that uses blocks to display content in the sidebars and header and footer. I am adding a several pages that will use panels. On these pages I want to remove the sidebar content and leave it up to panels to display those blocks, but I can't use the override all blocks setting because that also removes the header and footer blocks. Should I just create a tpl for each case (page-front.tpl.php, page-programs.tpl.php, etc) or is there a better way to accomplish this since I want the same page.tpl.php template for all panel pages?

sun’s picture

Status:Active» Fixed

If you use Panels Nodes, you could use page-panels-node.tpl.php.

For Panels pages, there is no common template file.

SocialNicheGuru’s picture

is there a way to make the panel pane theme like the blocks on drupal.org (contribution links for example):
light blue for the block
dark blue for the header
white text header
blue lettering

How would one theme panes in panels for this? Is this an addition to the css template?

Chris

Status:Fixed» Closed (fixed)

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

OpenChimp’s picture

I ended up using the following:
in template.php, I define extra variables that indicate if a page is a panels page and which panels page it is.

<?php
function zen_variables($hook, $vars) {
 
$panel_page = panels_page_get_current();
  if (
$panel_page):
   
$vars['is_panel_page'] = ($panel_page) ? TRUE : FALSE;
   
$vars['panel_page'] = $panel_page;
  endif;
}
?>

and in page.tpl.php I can use the

      <?php if (!$is_panel_page): ?>
        <?php if (!empty($sidebar_left)): ?>
          <div id="sidebar-left" class="column sidebar">
            <?php print $sidebar_left; ?>
          </div> <!-- /sidebar-left -->
        <?php endif; ?>
 
        <?php if (!empty($sidebar_right)): ?>
          <div id="sidebar-right" class="column sidebar">
            <?php print $sidebar_right; ?>
          </div> <!-- /sidebar-right -->
        <?php endif; ?>
      <?php endif; ?>

I could also have simply unset the region variables like this, but this seems a little less intuitive:

<?php
function zen_variables($hook, $vars) {
 
$panel_page = panels_page_get_current();
  if (
$panel_page):
       
$vars['sidebar_left'] = NULL;
       
$vars['sidebar_right'] = NULL;
  endif;
}
?>

I'm sure you could manipulate this code to create a page-panels.tpl.php template file, but since I really only wanted to slightly modify the template, the above solution seemed simpler.

Summit’s picture

Status:Closed (fixed)» Active

Hi,

Very interested in page-panels.tpl.php template file. May be you would file the solution for this also please Michael?
Thanks a lot in advance for considering this!

Greetings, Martijn

fatcrobat’s picture

Version:5.x-2.0-rc1a» 6.x-2.0-alpha3
Priority:Normal» Minor

Just add the following code to your template.php

<?php
function YOURTHEME_preprocess_page($vars) {

if (
$vars['node']->type == 'panel') {
   
$vars['template_file'] = 'page-panel';
  }
}
?>

then simply create a file called "page-panel.tpl.php" in your theme directory and clear the cache to apply the changes.

Summit’s picture

Hi,
Will this also work for panels 3?
Thanks a lot for your code already shown!
greetings,
Martijn

fatcrobat’s picture

should work for all panel nodes ;)

merlinofchaos’s picture

Status:Active» Closed (won't fix)

Panels 2 is no longer available and is unsupported. Marking all Panels 2 issues won't fix.

mlconnor’s picture

Version:6.x-2.0-alpha3» 6.x-3.3

I'm Using Panels 3.3 and this is still an issue from what I can tell. It would be nice to have page-panel-page.tpl.php

The issue is that I need to be able to make changes to the page.tpl.php in the event that a Panels Node page is being displayed. Is there an API call or variable present that would indicate to the themer whether or not the current page is a Panels Node?

The Panels system is flexible enough that the designer of the panel can finally put the breadcrumbs and page titles in a place within the panel that makes sense for that page. Turning off the title and breadcrumbs in the page.tpl.php is then necessary.

I looked at

function YOURTHEME_preprocess_page($vars) {

if ($vars['node']->type == 'panel') {
    $vars['template_file'] = 'page-panel';
}

but the node is the proper type already, not a Panels type. In my case, it is a Press Release. There are some hacks that are scanning the page content looking for CSS but I don't think that's acceptable. The other way to do it would be to implement theme_panels_pane and set a page variable but I'm concerned that it would cause unwanted behavior when minipanels were shown.

Any thoughts?

mlconnor’s picture

ok, i figured this out. the best way to do it is to use the theme_preprocess function and check panels_get_current_page_display() to see if there is a current panel. You can also dig into the Panel there and make some determinations about how your template should react. Then you can set variables for the page so your page.tpl.php can react accordingly.

In my case, I check to see if there is a pane of type page_title. If there is then I hide the title. I also do this for breadcrumbs. It works nicely!

Summit’s picture

Hi, Could you may be publish your code? would be great for others to look into. Thanks!
Greetings, Martijn

mlconnor’s picture

in my theme template...

<?php
/**
 * This function will look to see if you have
 * breadcrumb or page title panes from Panels
 * and if so, provide variables to the page
 * tempate which can be used to turn off
 * the standard page breadcrumbs or titles.
 */
function mlc_preprocess(&$variables, $hook) {
 
$show_breadcrumbs = TRUE;
 
$show_title = TRUE;

  switch (
$hook) {
    case
'page':
     
$panels_display = panels_get_current_page_display();
      if ( isset(
$panels_display->content ) ) {
        foreach (
$panels_display->content as $content_item ) {
          switch (
$content_item->type ) {
            case
'page_breadcrumb':
             
$show_breadcrumbs = FALSE;
              break;
            case
'page_title':
             
$show_title = FALSE;
              break;
          }
        }
      }
      break;
  }

 
$variables['show_breadcrumbs'] = $show_breadcrumbs;
 
$variables['show_title'] = $show_title;
}
?>

and in my page.tpl.php

  <?php if ( $show_breadcrumbs && $breadcrumb ) print $breadcrumb; ?>
  <?php if ( $show_title == TRUE && $title ) print "<h1 class="page-title">$title</h1>"; ?>
redben’s picture

This doesn't seem to work. At least in my case where i use a panel as a replacement from taxonomy/term/%

i also tried page_manager_get_current_page() but it returns an empty array....

Any help would be much appreciated

redben’s picture

Status:Closed (won't fix)» Active

Calling page_manager_get_current_page() from inside page.tpl gets the panel (or page) but in preprocess_page it return an empty array.
weird.

newswatch’s picture

Doesn't work on D6 + Panels 3 I am afraid.

newswatch’s picture

I put this (to go with my earlier configs):

function phptemplate_preprocess_page(&$variables) {
if  ($node = menu_get_object()) {
    $variables['node'] = $node;
    $suggestions = array();
    $template_filename = 'page';
    $template_filename = $template_filename . '-' . $variables['node']->type;
    $suggestions[] = $template_filename;
    $variables['template_files'] = $suggestions;
$variables['page']->type == 'panel';
    $template_filename = 'page-panel';
   }
}

Didn't work :(

merlinofchaos’s picture

Status:Active» Fixed

With Panels 3 you'd use page_manager_get_current_page() to retrieve the panel information. It includes quite a bit of data, so be sure to dsm() it.

dean.p’s picture

I also wanted to have a separate page.tpl.php to load for panels pages and after an hour looking online unsuccessfully for a solution, by fluke I just tried the following which seems to be working:

I created a Panels page called "Landing Page".
The URL for this page is (under settings > basic) is "landing/%tid/!term_name"

loading my page.tpl.php I saved a copy as page-landing.tpl.php (with a bit of text in the html to show me the template was in fact loading)

When I go to something like "www.mysite.com/landing/4/termname" the page-landing.tpl.php loads not page.tpl.php

This seems to work for panels and I thought it might be just reading the URL. So I tried a page-someotherurl.tpl.php for just some other node, but it did not work so it drupal is definately 'knowing' it's viewing a panel-page.

Using:
Drupal 6.17
Panels 6.x-3.5

Dimm’s picture

Drupal 6.17
Panels 6.x-3.7
node-panel-IDENTIFIER.tpl.php - not work

Dimm’s picture

It's work!!!
Put to field Template Identifier:
IDENTIFIER
not
node-panel-IDENTIFIER.tpl.php
!!!

http://drupal.org/node/704398#comment-2733078

Status:Fixed» Closed (fixed)

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

riverc’s picture

It seems that because the theme_page hook is implemented using page.tpl.php (This is confusing and takes awhile to figure out) this function

[x]_page($vars)

is *never* called, no matter if [x] = themename, themename_preprocess, phptemplate_preprocess, whatever.

I think some themes may change this behavior, but it looks to be default:

http://api.drupal.org/api/function/theme_page/6

The solution appears to be

1. Do not consider preprocess(vars,[hookval]) and preprocess_[hookval](vars) as coeval until you find out how [hookval] is implemented.

2. Testing behavior can be done with preprocess(vars,[hookval]) - I have used this to create a variety of template suggestions for panels. Two cases are important:

A. $hook = page, $vars['node']->type = 'panel';
B. $hook = node, $vars['node']->type = 'panel';

There are some other solutions out there for what I am about to suggest (There is a theme devel module) but you can also add a simple printout when developing to figure out what things can be templated and what are the possible template names. As was mentioned above, the $vars['template_files'] contains the template suggestions. I believe that they work in reverse order, the last template overriding any before it and so on.

You may do

function yourtemplate_preprocess(&$variables, $hook) {
  echo $hook . " \n";
  print_r($variables['template_files'];
}

and check out the results. As for getting

yourtemplate_preprocess_page()

to work, despite what it says here:

http://drupal.org/node/223440

I'm going with what I said above.

I installed the DEVEL module and it started calling yourtemplate_preprocess_page(). Whether or not my logic above makes any sense at all given that this happened, I don't know. But try it yourself and see if it works. With that in hand you can easily do something like

function yourtemplate_preprocess_page(&$variables) {
   switch($variables['node']->type) {
      case "panel":
        $variables['template_files'][] = "page-node-panel";
        // other stuff you might want to include?
      break;
      default:
      break;
   }
}

Else you will have to do this

function yourtemplate_preprocess(&$variables,$hook) {
   if($hook=="page") switch($variables['node']->type) {
      case "panel":
        $variables['template_files'][] = "page-node-panel";
        // other stuff you might want to include?
      break;
      default:
      break;
   }
}

The disadvantage is that you're going to be doing a bunch of extra function calls and if statements that you don't really need.

lord_of_freaks’s picture

Suscribing

EvanDonovan’s picture

Title:Theming panels - page-panels.tpl.php» Document how to create a page-PANEL-NAME.tpl.php/page-panel.tpl.php
Assigned:Unassigned» EvanDonovan
Category:support» task
Priority:Minor» Normal
Status:Closed (fixed)» Active

Decided to reopen this as a task to add to Advanced Help for Panels 3. Code snippet based on merlin's suggestion (with pointers on order of template suggestions from dekita):

You can add the following code to a module or a theme's template.php, then rebuild the theme registry, and you will have the ability to use page-panel.tpl.php or, more specifically, page-PANEL-NAME.tpl.php (where PANEL-NAME is the machine name of the panel in the Panels configuration):

<?php
/**
 * Implementation of MODULENAME/THEMENAME_preprocess_page().
 */
function MODULENAME_preprocess_page(&$vars) {
 
// if this is a panel page, add template suggestions
 
if($panel_page = page_manager_get_current_page()) {
   
// add a generic suggestion for all panel pages
   
$suggestions[] = 'page-panel';
   
// add the panel page machine name to the template suggestions
   
$suggestions[] = 'page-' . $panel_page['name'];
   
// merge the suggestions in to the existing suggestions (as more specific than the existing suggestions)
   
$vars['template_files'] = array_merge($vars['template_files'], $suggestions);
  }
}
?>

I'll try to submit an Advanced Help patch for this in a while, but wanted to at least post the snippet in the hopes that others would find it useful.

solomonrothman’s picture

Any major changes needed to use this with D7?

drecute’s picture

in Drupal 7, this worked:

<?php
function THEMENAME_preprocess_page(&$vars) {
    global
$theme_path;
    if(
$panel_page = page_manager_get_current_page()){
           
       
$target_menu = 'menu-sixth-form-college';
       
$current_path = menu_get_item();
       
       
$target_menu_links = menu_load_links($target_menu);
        foreach(
$target_menu_links as $links) {
           
$link_paths[] = $links['link_path'];
        }
       
$preferred_link_paths = $link_paths;
       
// if the current link is inside menu_load_link
       
if(in_array($current_path['href'], $preferred_link_paths)) {
           
$vars['theme_hook_suggestions'][] = 'page__sixthform';
        }
        if(
$panel_page['name'] == 'page-sixth_form_college') {
           
$vars['theme_hook_suggestions'][] = 'page__sixthform';
        }
    }
?>

I'm basically changing page templates based on whether the current page menu item is contained in a specific Drupal menu.

LTech’s picture

using Drupal 7
I copied page.tpl.php and renamed it page--panel.tpl.php. I then added echo "This is a test"; so I can test it out.
I then added to the end of my template.tpl.php file:
function Themename_preprocess_page(&$variables) {
// if this is a panel page, add template suggestions
if($panel_page = page_manager_get_current_page()) {

// add a generic suggestion for all panel pages
$variables['theme_hook_suggestions'][] = 'page__panel';

// add the panel page machine name to the template suggestions
$variables['theme_hook_suggestions'][] = 'page__' . $panel_page['name'];

//add a body class for good measure
$body_classes[] = 'page-panel';
}
}
But nothing happens when I do the above steps. What am I doing wrong?
I would like some code to the header of all my panel pages.
Thanks so much

LTech’s picture

any ideas why it isn't working? I'm not sure I named the template files correctly.
Is the machine name for my panel node_view? (This is what is under the name column under structure/pages).
Should the file be named page--node-view.tpl.php? Or page--panel-node-view.tpl.php
and where should I put the file? under themename/ or themname/templates

LTech’s picture

I got it working finally!
For drupal 7
in template.php:

function ThemeName_preprocess_page(&$vars) {
  // if this is a panel page, add template suggestions
  if($panel_page = page_manager_get_current_page()) {
    // add a generic suggestion for all panel pages
     $variables['theme_hook_suggestions'][] = 'page__panel';
    // add the panel page machine name to the template suggestions
    $variables['theme_hook_suggestions'][] = 'page__' . $panel_page['name'];
$object = $panel_page['contexts']['argument_entity_id:node_1'];
$result_array = get_object_vars($object);
$value = $result_array['restrictions']['type']['0'];
    if($panel_page['name'] == 'node_view' AND $value == 'product' ) {
            $vars['theme_hook_suggestions'][] = 'page__node_view_product';
        }
if($panel_page['name'] == 'node_view' AND $value == 'artist' ) {
            $vars['theme_hook_suggestions'][] = 'page__node_view_artist';
        }

and I created a files under ThemeName/templates
page--node_view_artist.tpl.php and
page--node_view_product.tpl.php

I hope this helps someone, it took me a long time to figure it out!
Thanks for your help

adambehnke’s picture

Here is the Drupal 6 version:

  // if this is a panel page, add template suggestions
  if($panel_page = page_manager_get_current_page()) {
    // add a generic suggestion for all panel pages
    $variables['template_files'][] = 'page-panel';
    // add the panel page machine name to the template suggestions
    $variables['template_files'][] = 'page-' . $panel_page['name'];
    $object = $panel_page['contexts']['argument_nid_1'];
    $result_array = get_object_vars($object);
    $value = $result_array['restrictions']['type']['0'];
    if($panel_page['name'] == 'node_view' AND $value == 'product' ) {
      $variables['template_files'][] = 'page-node_view-product';
    }
  }

Filenames follow D6 standards: page-node_view-product.tpl.php

robinthakur’s picture

Issue summary:View changes

Would I do the same thing if I'm overriding nodes of a specific content type? I just want to change the background on nodes of a specific type rather than on ALL panels. I have a javascript background rotator installed and need to override this for a particular page which uses panels layouts for this content-type's node display. I've tried altering the CSS for background, but this only works until the background rotator loads. I therefore want to remove the background rotator entirely but only for panels containing this specific content type, and therefore need the page layout...

Thanks,
Rob