SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante a CTools Style Plugins: Demo & Code Walk-Thru

Jumpstart Your Development with ZopeSkel
Jumpstart Your Development with ZopeSkelJumpstart Your Development with ZopeSkel
Jumpstart Your Development with ZopeSkelCristopher Ewing
 
Views Style Plugins
Views Style PluginsViews Style Plugins
Views Style Pluginsmwrather
 
Synapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephpSynapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephpSynapseindiaComplaints
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress WebsitesKyle Cearley
 
Ei cakephp
Ei cakephpEi cakephp
Ei cakephpeiei lay
 
CSS Overview and Examples
CSS Overview and ExamplesCSS Overview and Examples
CSS Overview and ExamplesMouli Kalakota
 
Introduction to Python and Django
Introduction to Python and DjangoIntroduction to Python and Django
Introduction to Python and Djangosolutionstreet
 
Drupalcamp Atlanta 2010 Design-to-Theme
Drupalcamp Atlanta 2010 Design-to-ThemeDrupalcamp Atlanta 2010 Design-to-Theme
Drupalcamp Atlanta 2010 Design-to-ThemeMediacurrent
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Thinkful
 
Melody Designer Training
Melody Designer TrainingMelody Designer Training
Melody Designer TrainingByrne Reese
 
Theming moodle technical
Theming moodle   technicalTheming moodle   technical
Theming moodle technicalAlex Walker
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 
Web Engineering - Introduction to CSS
Web Engineering - Introduction to CSSWeb Engineering - Introduction to CSS
Web Engineering - Introduction to CSSNosheen Qamar
 
Panels 3.0: The Powers Of Chaos Magic
Panels 3.0: The Powers Of Chaos MagicPanels 3.0: The Powers Of Chaos Magic
Panels 3.0: The Powers Of Chaos MagicChapter Three
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 

Semelhante a CTools Style Plugins: Demo & Code Walk-Thru (20)

Jumpstart Your Development with ZopeSkel
Jumpstart Your Development with ZopeSkelJumpstart Your Development with ZopeSkel
Jumpstart Your Development with ZopeSkel
 
Views Style Plugins
Views Style PluginsViews Style Plugins
Views Style Plugins
 
Synapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephpSynapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephp
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
Kick start @ css
Kick start @ cssKick start @ css
Kick start @ css
 
Ei cakephp
Ei cakephpEi cakephp
Ei cakephp
 
Cakeph pppt
Cakeph ppptCakeph pppt
Cakeph pppt
 
templates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtratemplates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtra
 
CSS Overview and Examples
CSS Overview and ExamplesCSS Overview and Examples
CSS Overview and Examples
 
Introduction to Python and Django
Introduction to Python and DjangoIntroduction to Python and Django
Introduction to Python and Django
 
Drupalcamp Atlanta 2010 Design-to-Theme
Drupalcamp Atlanta 2010 Design-to-ThemeDrupalcamp Atlanta 2010 Design-to-Theme
Drupalcamp Atlanta 2010 Design-to-Theme
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
 
Melody Designer Training
Melody Designer TrainingMelody Designer Training
Melody Designer Training
 
Theming moodle technical
Theming moodle   technicalTheming moodle   technical
Theming moodle technical
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Web Engineering - Introduction to CSS
Web Engineering - Introduction to CSSWeb Engineering - Introduction to CSS
Web Engineering - Introduction to CSS
 
Panels 3.0: The Powers Of Chaos Magic
Panels 3.0: The Powers Of Chaos MagicPanels 3.0: The Powers Of Chaos Magic
Panels 3.0: The Powers Of Chaos Magic
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Chromatique
ChromatiqueChromatique
Chromatique
 
Chromatique
ChromatiqueChromatique
Chromatique
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 

Último (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

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