Template overrides for specific panel panes

So after some time bashing my head against the wall, I finally figured out how to override specific panel panes in Drupal.

Panels comes with a template file called “panels-pane.tpl.php” but you can’t simply create a “panels-pane–my-pane.tpl.php” to override it, like you can with core template files or views.

This means you have to use a <a href=“http://drupal.org/node/223430"preprocess function to override the theme suggestion.

So let’s say you create a template file for your panel pane called “panels-pane–my-pane.tpl.php.” Using Drupal’s theme suggestions in a preprocess function in your theme’s template.php, you do this:

type == 'views_panes') { switch ($vars['pane']->subtype) { case 'portfolio-panel_pane_1': $vars['theme_hook_suggestions'][] = 'panels_pane__my_pane'; break; } } } One thing to note is that Drupal, in all it's wisdom to add unnecessary confusion to something that could and should be simple, changes the hyphens to underscores in the theme_hook_suggestions. What this means is that although you suggest "panels_pane__my_pane" as the theme hook name, Drupal will look for "panels-pane--my-pane" in the file name and not "panels_pane__my_pane" as anyone sane would expect. You will need to remember that you can't just tell Drupal to load a file called "my-pane.tpl.php" - it has to start with "panels-pane--". This is the type of thing that will make you carve a hole in the wall with nothing but your forehead, so keep it in mind. Finally, remember that you need to change MYTHEME to your theme's name. So there you go, I hope this helps clear up something that could be so simple but is stupidly intricate.

Be the first to know when I post cool stuff

Subscribe to get my latest posts by email.

powered by TinyLetter