I'm creating this issue to properly address the bug found in this issue: #1018726: Overriding the default panels-pane.tpl.php (the issue was for D6, not D7, and it should be closed).

From all the testing I've done, it's currently impossible to specify a template suggestion to a panel pane via a preprocess function in Drupal 7.

Tested with:

  • Drupal 7.2
  • Panels 3.x dev (2011-May-31 release) and Panels 3.0-alpha3
  • ctools 1.0-beta1

Testing Procedure

  1. Copied panels-pane.tpl.php to my theme's directory. Inserted new HTML markup and it worked
  2. Added the following code in my theme's template.php
    <?php
    function mytheme_preprocess_panels_pane(&$variables) {
        $variables['test'] = '<h1>weird funny test</h1>';
    }
    ?>
    
  3. Added <?php print $test; ?> which successfully outputted in panels-pane.tpl.php override.
  4. Added panels-pane-test.tpl.php file in my theme's directory and added unique HTML markup to distinguish it from panels-pane.tpl.php file
  5. Added following code to template.php:
    <?php
    function mytheme_preprocess_panels_pane(&$variables) {
        $variables['template_files'][] = 'panels-pane-test';
    }
    ?>
    
  6. and nothing happens once the cache is cleared.

I should mention that when doing a devel dpm of the panel pane variables in the preprocess function, there was no empty template_files array like in Drupal 6, which I'm guessing is at the heart of the issue. Nor did I see anywhere in the array where there would be any appropriate place to specify template overrides.

Hopefully this is thorough enough to help you determine the issue, and let me know how I can help.

Thanks,
Rene

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Headache’s picture

subscribe

jeff.maes’s picture

I have a working solution over here.

The difference with D6 is the way that D7 renames the template suggestions: You have to use underscores (_) in your template suggestions, which will be replaced with dashes (-).

<?php
/**
 * template.php
 *
 * Implementation of hook_preprocess_panels_pane().
 */
function mytheme_preprocess_panels_pane(&$variables) {
  if($variables['pane']->type == 'test') {
    $variables['theme_hook_suggestions'][] = 'panels_pane__test';  
  }  
}
?>

And your template suggestion is:

panels-pane--test.tpl.php
Headache’s picture

Status: Active » Closed (fixed)

Thank you, Jeff. It really works well.
Dunno why did I miss that point :/

bryancasler’s picture

bookmarking this for myself

rhache’s picture

Fantastic! Much appreciated.

samhassell’s picture

awesome thanks!

jenlampton’s picture

Title: Unable to add panel pane template suggestions » Automatically detect panel pane template suggestions by pane type
Category: bug » feature
Status: Closed (fixed) » Active

Could we add something like this so that these template files might be detected automatically?

function panels_preprocess_panels_pane(&$variables) {
  $base = 'panels_pane';
  $delimiter = '__';
  $variables['theme_hook_suggestions'][] = $base . $delimiter . $variables['pane']->type;  
}
merlinofchaos’s picture

Yes please. Can I get a patch?

Also, $type by itself, and then $type __ $subtype too?

jenlampton’s picture

Status: Active » Needs review
FileSize
800 bytes

good idea :) I also added "pane_" before the type and sub-type so it would match the classes.

merlinofchaos’s picture

I don't think the pane_ should be added to match the classes -- that's there to ensure no class collisions but in the case of a template suggestion that is not a risk.

merlinofchaos’s picture

Status: Needs review » Fixed

I remove the $prefix and committed this.

jenlampton’s picture

Thanks. :)

I added the prefix because the way I usually find out what to name a template file is to look at the source code and check out the classes applied. node--press-release for example. So yesterday when I was guessing at template name suggestions for panes, my first attempts had 'pane' in the type name since I had found the pane in the class name.

You're right, it't not necessary. But maybe some I'll write something up so people who won't look too deep into the code can figure out where to get a type, if not from the class.

Letharion’s picture

Component: Code » Documentation
Assigned: Unassigned » Letharion
Status: Fixed » Active

@jenlampton It would be great if you did decide to write something up. If you do, please post here.

I assign to myself and change to docs so we don't forget to get this in later :)

Charles wang’s picture

Thank you, Jeff. It really works now,oh!

kharbat’s picture

Can't override a custom module block template inside a panel pane!

Hi I have a custom module that generates a block. I have assigned the block inside a panel pane and i'm trying to override the template of the block but it's not working.

My block delta is: expenses-chart

The template file i use is: panels-pane--block--charts-expenses-chart.tpl.php

I would really appreciate any hints.. Because this sounds like a major problem

Regards,

bsuttis’s picture

FileSize
831 bytes

I was having trouble getting a suggestion to work and made a fix (based on the same code in block.module) that fixed it.

The issue was that I was trying to create a .tpl.php for a Views exposed form block inside a views pane.

The suggestion Panels provided was panels_pane__block__views--exp-search_standards-page.

Replacing the underscores with hyphens usually does the job, i.e. panels-pane--block.tpl.php worked for all blocks. But I needed even more specificity. I tried panels-pane--block--views--exp-search_standards-page.tpl.php to no avail.

After applying the patch attached, the suggestion provided is panels_pane__block__views__exp_search_standards_page and panels-pane--block--views--exp-search_standards-page.tpl.php works.

I'm not sure if I've just gotten confused by the way the template system replaces hyphens and underscores, but it works.

bsuttis’s picture

Status: Active » Needs review

Changing status.

merlinofchaos’s picture

If content subtype needs that strtr, then content type almost certainly will as well.

MiHeath’s picture

Can anyone confirm that the patch that jenlampton suggested works for views blocks. I'm still seeing an issue where if I create a view block, and load it into panels, using the block level template override is not working.

For instance, panels-pane--block.tpl.php and panels-pane.tpl.php work, but panels-pane--block--views-blockname-block.tpl is not being rendered at all.

Thoughts?

edit: bsuttis suggestion seems to help for views blocks used in panels, it's a simple fix to apply yourself, but could be useful if someone could put together a preprocess to temporarily fix this.

merlinofchaos’s picture

Status: Needs review » Fixed

Applied bsuttis' patch.

Status: Fixed » Closed (fixed)

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

jenlampton’s picture

I've added some documentation for how to determine a panels content pane template override, here: http://drupal.org/node/1678810

SNaKeMe’s picture

hi, i want to override the system type "node_view" of a panel ... but i dont get the suggestion with devel ... for the panels-pane.tpl.php file ...

Link in Panels
/admin/structure/pages/nojs/operation/node_view/handlers/node_view_panel_context_7/content

CSS-Output

<div id="block-system-main" class="block block-system block-odd block-count-4 block-region-content">
<div class="block-inner clearfix">
<div class="block-content content no-title">
<div class="contextual-links-region">
<div class="panel-flexible panels-flexible-33 clearfix">
<div class="panel-flexible-inside panels-flexible-33-inside">

Tested filenames for template corolla:
panels-pane--node--7.tpl.php
panels-pane--flexible--33.tpl.php
panels-pane--node-view--7.tpl.php

Searched on google and so on ...

aschiwi’s picture

There is a new module that makes using pane templates really easy: http://drupal.org/project/pps

rhache’s picture

The Clean Markup Module also makes the customization of panel region and panel pane wrappers very easy.

  • Commit 024e636 on 7.x-3.x, 7.x-3.x-i18n, 8.x-3.x by merlinofchaos:
    Issue #1178334 by bsuttis: dashes in pane suggestions caused problems.
    
    
  • Commit ac97790 on 7.x-3.x, 7.x-3.x-i18n, 8.x-3.x by merlinofchaos:
    Issue #1178334 by jenlampton: Add template suggestions for panel pane...