Panels magic
This blog post is more than 2 years old, so the content may be out of date.
I love unexpected discoveries.
Drupal's Panels module seems to find its way into most of my site builds, along with custom layouts, panel-panes and all sorts of goodness.
I used to declare custom panel layouts this way:
<?php /** * Implementation of hook_panels_layouts(). */ function modulename_layoutname_panels_layouts() { $items['layoutname'] = array( 'title' => t('NAME OF LAYOUT'), 'icon' => 'layoutname.png', 'theme' => 'panel_modulename_layoutname', 'css' => 'layoutname.css', 'panels' => array( // 'regions' used in the layout 'topleft' => t('Top Left pane'), 'topmiddle' => t('Top Middle pane'), 'topright' => t('Top Right pane'), 'bottomleft' => t('Bottom Left pane'), 'bottomright' => t('Bottom Right pane'), ), ); return $items; }
Turns out we don't need that excessively long function definition...it can be declared as a simple variable instead:
<?php /** * Implementation of hook_panels_layouts(). */ $plugin = array( 'title' => t('NAME OF LAYOUT'), 'icon' => 'layoutname.png', 'theme' => 'panel_modulename_layoutname', 'css' => 'layoutname.css', 'panels' => array( // 'regions' used in the layout 'topleft' => t('Top Left pane'), 'topmiddle' => t('Top Middle pane'), 'topright' => t('Top Right pane'), 'bottomleft' => t('Bottom Left pane'), 'bottomright' => t('Bottom Right pane'), ), );
This relies on some ctools plugin-processing magic, which specifically looks for the $plugin variable (and this approach should work for all ctools plugins). I can see myself using this a lot :-)


Comments
#harrison22[DGD... (not verified)
June 6, 2011 - 2:19pm
Permalink
Hey - I am really glad to find this. Good job!
prokCarkfax (not verified)
September 3, 2011 - 7:50pm
Permalink
Just making my first post at deglos.com, which seems to be a wonderful forum!
Add new comment