[Drupal] How to create a custom content pane for panels by programatically in drupal 6

March 31, 2014 - 16:44

Panels in drupal is a very usefull feature for displaying the contents in a well organized manner. The site administrator will have full control over the panels.Creating panels via User interface is not a complex task. But there may arise situation when you need to create this via code. This article explains how to achieve this via code.

Creating a custom content pane using the ctools content type.

Step 1) In the custom module implement the hook_ctools_plugin_directory , to know where the ctools plugin is actually stored

For eg :
A custom_module {sites/all/modules/custom/custom_module/custom_module.module} file should implement hook_ctools_plugin_directory()

function custom_module_ctools_plugin_directory($module, $plugin) {
  if ($module == 'ctools') {
    return 'plugins/' . $plugin;

This is to let the system know we implement plugins. This will search for the content types in the directory plugins/content_types

Step 2) Create a directory named plugins in the custom module {sites/all/modules/custom/custom_module/plugins)

Step 3) Create a sub directory content_types in the plugins directory {sites/all/modules/custom/custom_module/plugins/content_types}

Step 4) Next is to create a content type.

Create a file with extension .inc for eg : example_pane.inc ie, content_type_name.inc. This is the content type. Each content type must have
unique name , so it is better to name the module name as the content type itself if our module has only one ctools plugin content type.

Step 5) In the file example_pane.inc we can write the call back function to supply the list of the content types.
ie, the Implementation of MODULENAME_FILENAME_content_type_ctools_content_types

Here is an example :

function custom_module_example_pane_ctools_content_types() {
  return array(
    'single' => TRUE,
    'title' => t('Example Custom Content Pane'),
    'description' => t('Example Desctiption'),
    'category' => t('Example Category'),

Here category defines where our content type shows up in the "add content" dialog. If it is not previously defined ctools will create a
new one.

Step 6) Next is the Implementation of MODULENAME_FILENAME_content_type_render

Eg :

function custom_module_example_pane_content_type_render($subtype, $conf, $panel_args, $context) {
  $block = new stdClass();
  $block->title = 'Example Title';
  $block->content = 'Example Content';
  return $block;

This function will return the content that is to be displayed in the panel.

Happy Coding.

Get Drupal updates straight to your inbox


Post your comments / questions