A simple custom panels pane style

If you'd like to define a few super-simple custom panels pane styles, here's the bare bones code.

In a custom module:

<?php

/**
* Implements hook_ctools_plugin_directory().
*/
function grasmash_panels_ctools_plugin_directory($module, $plugin) {
  if (
$module == 'panels' && $plugin == 'styles') {
    return
'plugins/' . $plugin;
  }
}
?>

In plugins/styles/gold.inc:

<?php
<?php

/**
* @file
* Defines "Gold Border" style.
*/

/**
* Implements hook_panels_style_info().
*/
function grasmash_panels_gold_panels_styles() {
  return array(
   
'title' => t('Gold Border'),
   
'description' => t('Displays the pane with a gold border.'),
   
'render pane' => 'grasmash_panels_gold_render_pane',
  );
}

/**
* Render callback for "gold" panels pane style. Mimics default panel pane.
*/
function theme_grasmash_panels_gold_render_pane($vars) {
  return
theme('panels_pane', array(
   
'content' => $vars['content'],
   
'pane' => $vars['pane'],
   
'display' => $vars['display'],
  ));
}
?>

In your theme:

<?php
/**
* Implements template_preprocess_panels_pane().
*/
function grasmashtheme_preprocess_panels_pane(&$vars) {
  if (!empty(
$vars['pane']->style['style'])) {
   
$style = $vars['pane']->style['style'];
   
$vars['classes_array'][] = 'panels-pane-style-' . drupal_clean_css_identifier($style);
  }
}
?>
    .panels-pane-style-gold {
      border: 4px solid gold;
    }
Drupal Version Compatibility: 

Comments

I really liked your article.Really thank you!

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.