As promised earlier in my presentation on building Drupal sites using CCK, Views and Panels, here is an article on how to write a custom panel, that implements a custom layout.

I called it mypanel, and it implements a new layout that is best represented by the icon on the right.

Only two functions are required to implement a basic panel. One is an implementation of the panels_layouts hook, and the other is a theme function.

The first function returns an array with certain data, such as the module that implements this panel, a title, the theme function that generates the panel, the icon for the pane, and the css file to use. Then a list of content areas that this panel implements.

The second function just puts some HTML and places $content[areaname] in the appropriate places.

Here is the code for the panel. Of course you can decide to use pure CSS without tables.

function mypanel_panels_layouts() {
$items['mypanel'] = array(
'module' => 'mypanel',
'title'  => t('mypanel home'),
'theme'  => 'mypanel',
'icon'   => 'mypanel.png',
'css'    => 'mypanel.css',
'content areas'      => array(
'top_story'        => t('Top Story'),
'op_ed'            => t('Op Ed'),
'op_ed_list'       => t('Op Ed list'),
'banner'           => t('Banner'),
'gallery'          => t('Gallery'),
'featured_gallery' => t('Featured Ads'),
'links'            => t('Links'),
return $items;
function theme_mypanel($id, $content) {
$output = <<<EOT
<table id="fp-top-story">
<td class="top-story">$content[top_story]</td>
<table id="fp-op_ed">
<td width="50%" class="oped" valign="top">
<td width="50%" valign="top" class="oped_list">
<div id="banner">
<div class="front-page-banner">$content[banner]</div>
<table id="fp-gallery">
<td valign="top" width="50%" class="creative-gallery">
<td valign="top" width="50%" class="featured-gallery">
<div id="page-links-main">
return $output;

And there you have it ...


Wed, 2007/06/06 - 17:02

Thanks for the tutorial. I've searched high and low for info on how to do this and your site is the only one I found. Would the sample code be placed in mypanel.module file? If not, where does this code need to go?

Wed, 2007/06/06 - 17:25

You're the man! Thanks for the prompt response.

Wed, 2007/06/06 - 17:47

I'm new to drupal 5.0 but it looks like you need to create an .info file as well in order to get this to work.

Thu, 2007/07/19 - 07:18


With panels 2 (drupal 5.1) you can choose whatever layout you like by selecting the flexible panel possibility.
That way you don't need to build a module, and you have a nice panels-integrated result!


Tue, 2008/01/08 - 06:23

Well, I give up. I try yo implement this on a Panels 5.x-1.2 creating the .inc, .css and .png files on the layout folder and the module dont recognize it. Also try to update module with no effects. What i'm doing wrong?

thanks in advance

Tue, 2008/10/07 - 21:03

This was exactly what I needed; merlin had mentioned this as how you do your own styles without putting them in the panels layout directory, but not anything special needed for a module.

BTW, there is a random "aaa" at the end of the article.

Is your Drupal or Backdrop CMS site slow?
Is it suffering from server resources shortages?
Is it experiencing outages?
Contact us for Drupal or Backdrop CMS Performance Optimization and Tuning Consulting