Академический Документы
Профессиональный Документы
Культура Документы
English
Page 1
Business
Open Technology
Clients
Working at Mearra
Blog
Contact
Sampo Turve
Planet Drupal Sampo has over 4 years of experience in working as a developer on digital media projects. Sampo has been working intensively with Drupal since 2007 and has strong knowledge of web programming languages and web standards. As Mearra's youngest employee Sampo can be lovingly teased by calling him a Wunderkind. ;) That said, Sampo enthusiastically takes on large projects with impressive results. Sampo is located in Mearra's Turku office.
Drupal 7
Color module
Theming
Modules
This is a tutorial how you can easily take advantage of Color module on your custom theme on Drupal 7. Color is a module that comes with the Drupal core. It offers very nice re-coloring of your theme with minimal coding. Many popular themes are taking advantage of the Color module, such as AdaptiveTheme, BlogBuzz, Pixture Reloaded, RootCandy, Sky and multiple others.
This serie
Becoming friends with the Drupal Color module Part 2
Blogauthors
Agnese telce Cristian Andrei Emma Mkinen Ernests Gabrns Henri Hirvonen Ilari Mkel Ilze Zaria Jani Palsamki Joonas Kiminki Juha Niemi
http://mearra.com/blogs/sampo-turve/becoming-friends-drupal-color-module-part-1
19/06/2012 21:26:36
Page 2
Teemu Merikoski
Step 1. If you don't have a custom theme, create one. It's easy. I will be using my custom theme called
ss in this tutorial.
Step 2. Create a directory called color into your custom theme directory (I have: sites/all/themes/ss/ color). Step 3. Add file called color.inc to the color folder (I have: sites/all/themes/ss/color/color.inc). Step 4. Add a image file called base.png to the color folder. We don't use this on the basic configuration but Color requires it. You can copy one from the attached archive at the end of this post or here. Step 5. Create a CSS file called colors.css into your theme's directory where you have your CSS styles located (I have: sites/all/themes/ss/styles/colors.css) Note: We could also use the theme's default
Latest inMearrablog
stylesheet that you might have, but I prefer to keep Color module stuff in its own file.
Now your theme directory should look something like this:
Publish your module code It's the best thing for you and your customer
Joonas Kiminki - 18.3.2012
work?
Vesa Palmu - 15.3.2012
<?php /** * PART 1. Basic Color module settings */ $info = array(); // Define the possible replaceable items and their labels. $info['fields'] = array( 'bg' => t('Main background'), 'link' => t('Link color'), 'text' => t('Text color'), 'titles' => t('Titles'), 'menu_item_color' => t('Menu item link color'), 'menu_item_a_bg' => t('Menu active item background color'), 'menu_item_a_color' => t('Menu active item link color'), );
Step 6.1. Then let's define the color schemes for the site. Keys in here are the same ones that were used above. The Hex color code values (for example #ffffff for white, #ff7f00 for orange, etc) are the values that the Color module is going to replace from our CSS file (will be defined later). Good note by Kristi: You should use only lowercase letters, otherwise Color won't pick up your colors correctly. Here we have two schemes defined, one called default (Our site default colors) and one called drupal_
Getintouch
Helsinki
+358 20 7912 940 Emma Mkinen
Riga
+371 29 849 696 Ernests Gabrans
Turku
+358 44 010 0667 Juha Niemi
Valmiera
+371 26 426 777 Mikelis Zalais
MORE
http://mearra.com/blogs/sampo-turve/becoming-friends-drupal-color-module-part-1
19/06/2012 21:26:36
Page 3
// Define the CSS file(s) that we want the Color module to use as a base. $info['css'] = array( 'styles/colors.css', );
Step 7. Your theme should also be aware that there's a new stylesheet. Add this into your theme's .info file (I have sites/all/themes/ss/ss.info).
; Add our stylesheet for the Color module to override. stylesheets[all][] = styles/colors.css
Step 8. CSS properties. Pretty simple styles, just for the body and menu item backgrounds and some text colors. Note: The Hex color codes are the same than the ones we defined in the previous step's default scheme.
/* Site background color */ body { background-color: #ffffff; color: #777777; } /* Lists */ ul, li, ul li.collapsed, ul li.expanded, ul li.leaf { color: #777777; } /* Site titles */ h1, h2 { color: #333333; } /* Main content area links */ #main-content a:link, #main-content a:visited, #main-content a:hover, #main-content a:focus, #main-content a:active { color: #ff7f00; } /* Main menu links */ #site-menu ul li a { color: #666666; } /* Main menu active links */ #site-menu ul li.active-trail a, #site-menu ul li a.active { background: #eeeeee; color: #000000; }
http://mearra.com/blogs/sampo-turve/becoming-friends-drupal-color-module-part-1
19/06/2012 21:26:36
Page 4
/***** Advanced Color settings - Defaults. Will be used in the Part 2. *****/ /** * Default settings for the advanced stuff. * No need to edit these if you just want to play around with the colors. * Color wants these, otherwise it's not going to play. * * We dive deeper into these in the Part 2. Advanced Color settings */ // Files we want to copy along with the CSS files, let's define these later. $info['copy'] = array(); // Files used in the scheme preview. $info['preview_css'] = 'color/preview.css'; $info['preview_js'] = 'color/preview.js'; $info['preview_html'] = 'color/preview.html'; // Gradients $info['gradients'] = array(); // Color areas to fill (x, y, width, height). $info['fill'] = array(); // Coordinates of all the theme slices (x, y, width, height) // with their filename as used in the stylesheet. $info['slices'] = array(); // Base file for image generation. $info['base_image'] = 'color/base.png';
Step 11. You need to clear the caches of your Drupal site and let your theme know about the new files. Head to your site's Performance section (admin/config/development/performance) and click the 'Clear all caches' button. Step 12. Enable the Color module if you already haven't. Step 13. Visit your theme settings page (I have admin/appearance/settings/ss). Now the Color module has detected that you have its stuff in your theme directory, and is showing you the color picker:
http://mearra.com/blogs/sampo-turve/becoming-friends-drupal-color-module-part-1
19/06/2012 21:26:36
Page 5
Step 14. Ready. Now you can select from your predefined schemes or with just a couple of clicks, you can turn your site into a pink dream!
P.S. If you have issues with the fields not appearing correctly at the settings form, take a look at Theme settings form should include newly added colorable elements. Attachment color-module-example-ss-basic.zip Size 54.55 KB
http://mearra.com/blogs/sampo-turve/becoming-friends-drupal-color-module-part-1
19/06/2012 21:26:36
Page 6
Wonderful Tutorial
Submitted by Samuel Ayela (not verified) on 27. November 2011 - 1:36 Thank you very much for such a wonderful tutorial.
reply
Hi,
Submitted by Perry Prabhat Jain (not verified) on 27. November 2011 - 22:57 Hi, Thanks for the tutorial, it worked, however I was not able to get preview image. I am using omega 3.0 theme. I will look forward for the next part in the series. Thanks, Perry.
reply
Hi,
Submitted by Sampo Turve on 28. November 2011 - 8:38 Hi, The preview builds out of three different parts: HTML, CSS and the Javascript that is handling the preview. It's not meant to be working in this basic tutorial. I will try to get the Part 2 out asap, and I will cover the preview handling there also.
reply
Omega
Submitted by Stijn (not verified) on 28. November 2011 - 15:28 Perry, I'm trying to get this working with Omega 3.0 to but something is going wrong.... Did you edit Omega itself or are you working with a subtheme?
reply
sub-theme of course!!
Submitted by Perry Jain (not verified) on 29. November 2011 - 21:47 sub-theme of course!!
reply
http://mearra.com/blogs/sampo-turve/becoming-friends-drupal-color-module-part-1
19/06/2012 21:26:36
Page 7
Step 10.
Submitted by Syg (not verified) on 16. January 2012 - 12:37 Step 10. If you add the ['preview_html'] in the color.inc configuration array, the color module will search for the preview.html file in your theme directory. So you have to copy it from the module to your theme or delete this line from the config file. ---color.inc--// Files used in the scheme preview. $info['preview_css'] = 'color/preview.css'; $info['preview_js'] = 'color/preview.js'; $info['preview_html'] = 'color/preview.html'; ---color.module--// Attempt to load preview HTML if the theme provides it. $preview_html_path = DRUPAL_ROOT . '/' . (isset($info['preview_html']) ? drupal_get_path('theme', $theme) . '/' . $info['preview_html'] : drupal_get_path('module', 'color') . '/preview.html'); => This works for me without copying the preview.html file ---color.inc--// Files used in the scheme preview. $info['preview_css'] = 'color/preview.css'; $info['preview_js'] = 'color/preview.js';
reply
Step 9.
Submitted by Syg (not verified) on 16. January 2012 - 13:08 Step 9. /* * Implements template_process_page(). */ function YOURTHEMENAME_process_page(&$vars, $hook) { // Hook into color.module. if (module_exists('color')) { _color_page_alter($variables); } } Be carefull $variables is different from $vars. You pass the wrong variable name.
http://mearra.com/blogs/sampo-turve/becoming-friends-drupal-color-module-part-1
19/06/2012 21:26:36
Page 8
Case sensitivity in D7
Submitted by Kristi (not verified) on 17. February 2012 - 1:24 I spent a day trying to figure out a problem where the color module wasn't replacing my hex codes as expected, but instead was color shifting all my values. Turns out, the default color scheme is case sensitive! Check out: http://drupal.org/node/1415206.
reply
thanks
Submitted by bekasu (not verified) on 3. June 2012 - 6:04 thanks for the info and the link at the bottom referring to the problem encountered when adding a new colorable item to the 'custom' preset.
reply
E-mail
The content of this field is kept private and will not be shown publicly.
Homepage
Subject
Comment *
Save
http://mearra.com/blogs/sampo-turve/becoming-friends-drupal-color-module-part-1
19/06/2012 21:26:36
Page 9
Stay up to date
Subscribe to Mearra's newsletter! We will send a newsletter twice a year to inform you
OlliErinko @kunfu_code #android, if you're buying a phone now. Might be worth waiting for iPhone 5 though.
20.06.2012 - 09:43
2012 Mearra
http://mearra.com/blogs/sampo-turve/becoming-friends-drupal-color-module-part-1
19/06/2012 21:26:36