We’ve been recently using more of Panels in our Drupal projects, and for the most part it’s been very rewarding as we’ve been delving deeper into it.

But one issue that I’ve had with Panels recently is how to create template (tpl) overrides for a specific panel panes. There is a panels-pane.tpl.php, but that’s it. You can’t create a panels-pane-my-pane.tpl.phpoverride, like you can with core template files like node.tpl.phpor with views, for example. This means that you have to potentially resort to adding logic in your panels-pane.tpl.php, which we are loathe to do there.

Well, it turns out that there is a way, via the magic of a preprocess function. I initially found an issue on the Panels issue queue and a post on the Panels group, but the information provided was incomplete so I figured I would provide a more thorough example here if anybody gets stuck like I did.

In the scenario that we encountered, I was trying to insert the node title as a pane in a panel node template for a specific content type. By default, the node title panel pane was output as follows:

Node Title

Pane Content


Far from what I consider ideal semantics. What we really wanted was something like:

Node Title

In order to achieve this ideal scenario, we need to add a preprocess function in our theme’s template.phpor in a custom module. Here’s what worked for my particular situation:

function MYTHEME_preprocess_panels_pane(&$vars) {
if ($vars['pane']->type == 'node_title') {
$vars['template_files'][] = 'panels-pane-node-title';

In this case, I’m specifying that if the pane is of the node title type, use the panels-pane-node-title.tpl.php template file. It’s simple and very effective. You just have to replace MYTHEMEwith the name of your theme or module.