SlideShare a Scribd company logo
CTools Style Plugin
Demo & Code Walk-Through
Amber Himes
IRC/d.o: agentolivia | Twitter: @amberhimes
What is CTools?
• CTools = Chaos Tool Suite
• A contrib project on drupal.org
• Developer APIs and Tools
• Page Manager
• drupal.org/project/ctools
What is a CTools
plugin?
• A plugin is way for a module to allow
another module or theme to implement a
piece of functionality
• Useful when you want to add or alter
existing features of a module.
• Types of plugins include contexts,
content types, layouts, and style
Style Plugins
• With a Style Plugin, define:
• a settings form
• how to render settings in a template
Where do I use it?
• In the Panels interface,
click on gear of pane
and select “Style”
• In Panelizer or
Panopoly, click the
Paintbrush icon
Panopoly Example
Demo
• Weber County Library in Ogden, UT
• Panopoly distro, Panels IPE (In-Place Editor)
• Live Preview of panel pane styles
Overview of steps
• Create a custom module
• Tell CTools about our plugin files
• Define our $plugin array
• Define our theme and form hooks
• Create our template file and make use
of returned values
My Module Files
...explained
My Module Files
weber_styles.module
Implements hook_ctools_plugin_directory
1 <?php
2 function
weber_styles_ctools_plugin_directory(
$module, $plugin) {
3 return 'plugins/' . $plugin;
4 }
$plugin gotchas
• Define $plugin array inside our .inc but
outside any function
• CTools knows to look for $plugin because
we told it to in:
hook_ctools_plugin_directory()
$plugin array
Follow along...
https://gist.github.com/agentolivia/5745929
=> http://tinyurl.com/ctools-style-gist <=
‘render pane’
• corresponds to the theme function that
renders the pane, without “theme_”
• If the theme function is named
theme_panesandblocks_render_pane
then the value for ‘render pane’ is
‘panesandblocks_render_pane’
‘render pane’
‘region pane’
• corresponds to the theme function that
renders the region, without “theme_”
• If the theme function is named
theme_panesandblocks_render_region
then the value for ‘render region’ is
‘panesandblocks_render_region’
‘pane settings form’
• The full name of the function that returns
the settings form. For example:
panesandblocks_settings_form
• The corresponding function:
function panesandblocks_settings_form
($style_settings)
• Use Form API to build form components.
Set default values using $style_settings
‘hook theme’
• Defines theme functions and variables for
pane and region
• Pane and Region will each have their own
arrays of hook theme information
• Array key = the first parameter of theme()
returned in the corresponding theme_
function
hook
theme
key
hook theme variables
render pane theme fxn
1 function
theme_panesandblocks_render_pane($vars)
{
2 $settings = $vars['settings'];
3 $content = $vars['content'];
4
5 return
theme('panesandblocks_theme_pane',
array('content' => $content,
6 'settings' => $settings));
7 }
vars in template files
• Whatever variables I listed in $plugin’s
‘hook theme’ are passed into the theme
function which make these values available
in my template files
• $content and $settings seem to be the two
preferred choices for variables in hook
theme
vars gotchas
• $settings is an array
• $content is an object
tpl vars gotchas
• $settings is an array
• i.e. $settings[‘heading_classes’]
• $content is an object
• i.e. $content->title
use of vars in tpl
1 <?php if (isset($content->title)): ?>
2 <h3 class="<?php print
(isset($settings['heading_classes'])) ?
$settings['heading_classes'] : ''; ?>">
<?php print $content->title; ?></h3>
3 <?php endif; ?>
build settings form
Print values from
settings form in tpl.php
• Use php print statements to output
settings form values as CSS classes
in your pane template file
$settings in .tpl.php
Apply CSS
• No need to bury a CSS file in a plugin
directory
• Do inspect the elements to make sure
classes have been applied as expected
Inspect!
Troubleshooting tips
• Add a css file through drupal_add_css at
the top of your template file to get the
preview working right away
• Check all instances of panel panes to make
sure they are rendering correctly, as this
template file will override the panels-
pane.tpl.php.
• Add logic to theme function as needed
Questions?
• Slides: http://tinyurl.com/ctools-style
• Code: http://tinyurl.com/ctools-style-gist
• Twitter: @amberhimes
• IRC/drupal.org agentolivia

More Related Content

PPT
Power Theming
ZIP
Presentation.Key
PPT
Drupal Lightning FAPI Jumpstart
PDF
Tapa #PCM15
PDF
Drupal Front End PHP
PDF
Laying the proper foundation for plugin and theme development
PDF
Seven deadly theming sins
PDF
Introduction to Drupal (7) Theming
Power Theming
Presentation.Key
Drupal Lightning FAPI Jumpstart
Tapa #PCM15
Drupal Front End PHP
Laying the proper foundation for plugin and theme development
Seven deadly theming sins
Introduction to Drupal (7) Theming

Similar to CTools Style Plugins: Demo & Code Walk-Thru (20)

PDF
Learning PHP for Drupal Theming, DC Chicago 2009
PPT
Render API - Pavel Makhrinsky
KEY
PSD to Drupal - Introductory Drupal Theming
PDF
Melody Designer Training
PPT
Drupal 7 theme by ayushi infotech
PDF
Theme Gurus
PDF
Speed up the site building with Drupal's Bootstrap Layout Builder
PPTX
Drupal theming
PPTX
WordPress theme setting page
PPTX
Drupal theme development
PDF
Intro to Theming Drupal, FOSSLC Summer Camp 2010
PPTX
Responsive themeworkshop wcneo2016
PDF
Design to Theme @ CMSExpo
PPTX
Theming Drupal: Beyond the Look and Feel
PDF
Nanocon Taiwan
PPTX
Drupal Theme Development
PPTX
Building Potent WordPress Websites
KEY
Leveraging the Chaos tool suite for module development
PDF
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
PDF
WordPress customizer: for themes and more
Learning PHP for Drupal Theming, DC Chicago 2009
Render API - Pavel Makhrinsky
PSD to Drupal - Introductory Drupal Theming
Melody Designer Training
Drupal 7 theme by ayushi infotech
Theme Gurus
Speed up the site building with Drupal's Bootstrap Layout Builder
Drupal theming
WordPress theme setting page
Drupal theme development
Intro to Theming Drupal, FOSSLC Summer Camp 2010
Responsive themeworkshop wcneo2016
Design to Theme @ CMSExpo
Theming Drupal: Beyond the Look and Feel
Nanocon Taiwan
Drupal Theme Development
Building Potent WordPress Websites
Leveraging the Chaos tool suite for module development
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
WordPress customizer: for themes and more
Ad

Recently uploaded (20)

PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
TLE Review Electricity (Electricity).pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
A Presentation on Artificial Intelligence
PDF
August Patch Tuesday
PDF
A comparative analysis of optical character recognition models for extracting...
PPT
Teaching material agriculture food technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
cloud_computing_Infrastucture_as_cloud_p
Heart disease approach using modified random forest and particle swarm optimi...
TLE Review Electricity (Electricity).pptx
NewMind AI Weekly Chronicles - August'25-Week II
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
Assigned Numbers - 2025 - Bluetooth® Document
SOPHOS-XG Firewall Administrator PPT.pptx
Empathic Computing: Creating Shared Understanding
Programs and apps: productivity, graphics, security and other tools
A Presentation on Artificial Intelligence
August Patch Tuesday
A comparative analysis of optical character recognition models for extracting...
Teaching material agriculture food technology
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
A comparative study of natural language inference in Swahili using monolingua...
Network Security Unit 5.pdf for BCA BBA.
cloud_computing_Infrastucture_as_cloud_p
Ad

CTools Style Plugins: Demo & Code Walk-Thru

  • 1. CTools Style Plugin Demo & Code Walk-Through Amber Himes IRC/d.o: agentolivia | Twitter: @amberhimes
  • 2. What is CTools? • CTools = Chaos Tool Suite • A contrib project on drupal.org • Developer APIs and Tools • Page Manager • drupal.org/project/ctools
  • 3. What is a CTools plugin? • A plugin is way for a module to allow another module or theme to implement a piece of functionality • Useful when you want to add or alter existing features of a module. • Types of plugins include contexts, content types, layouts, and style
  • 4. Style Plugins • With a Style Plugin, define: • a settings form • how to render settings in a template
  • 5. Where do I use it? • In the Panels interface, click on gear of pane and select “Style” • In Panelizer or Panopoly, click the Paintbrush icon Panopoly Example
  • 6. Demo • Weber County Library in Ogden, UT • Panopoly distro, Panels IPE (In-Place Editor) • Live Preview of panel pane styles
  • 7. Overview of steps • Create a custom module • Tell CTools about our plugin files • Define our $plugin array • Define our theme and form hooks • Create our template file and make use of returned values
  • 10. weber_styles.module Implements hook_ctools_plugin_directory 1 <?php 2 function weber_styles_ctools_plugin_directory( $module, $plugin) { 3 return 'plugins/' . $plugin; 4 }
  • 11. $plugin gotchas • Define $plugin array inside our .inc but outside any function • CTools knows to look for $plugin because we told it to in: hook_ctools_plugin_directory()
  • 13. ‘render pane’ • corresponds to the theme function that renders the pane, without “theme_” • If the theme function is named theme_panesandblocks_render_pane then the value for ‘render pane’ is ‘panesandblocks_render_pane’
  • 15. ‘region pane’ • corresponds to the theme function that renders the region, without “theme_” • If the theme function is named theme_panesandblocks_render_region then the value for ‘render region’ is ‘panesandblocks_render_region’
  • 16. ‘pane settings form’ • The full name of the function that returns the settings form. For example: panesandblocks_settings_form • The corresponding function: function panesandblocks_settings_form ($style_settings) • Use Form API to build form components. Set default values using $style_settings
  • 17. ‘hook theme’ • Defines theme functions and variables for pane and region • Pane and Region will each have their own arrays of hook theme information • Array key = the first parameter of theme() returned in the corresponding theme_ function
  • 20. render pane theme fxn 1 function theme_panesandblocks_render_pane($vars) { 2 $settings = $vars['settings']; 3 $content = $vars['content']; 4 5 return theme('panesandblocks_theme_pane', array('content' => $content, 6 'settings' => $settings)); 7 }
  • 21. vars in template files • Whatever variables I listed in $plugin’s ‘hook theme’ are passed into the theme function which make these values available in my template files • $content and $settings seem to be the two preferred choices for variables in hook theme
  • 22. vars gotchas • $settings is an array • $content is an object
  • 23. tpl vars gotchas • $settings is an array • i.e. $settings[‘heading_classes’] • $content is an object • i.e. $content->title
  • 24. use of vars in tpl 1 <?php if (isset($content->title)): ?> 2 <h3 class="<?php print (isset($settings['heading_classes'])) ? $settings['heading_classes'] : ''; ?>"> <?php print $content->title; ?></h3> 3 <?php endif; ?>
  • 26. Print values from settings form in tpl.php • Use php print statements to output settings form values as CSS classes in your pane template file
  • 28. Apply CSS • No need to bury a CSS file in a plugin directory • Do inspect the elements to make sure classes have been applied as expected
  • 30. Troubleshooting tips • Add a css file through drupal_add_css at the top of your template file to get the preview working right away • Check all instances of panel panes to make sure they are rendering correctly, as this template file will override the panels- pane.tpl.php. • Add logic to theme function as needed
  • 31. Questions? • Slides: http://tinyurl.com/ctools-style • Code: http://tinyurl.com/ctools-style-gist • Twitter: @amberhimes • IRC/drupal.org agentolivia