Miguel Rodríguez does effective software development.

How to theme Drupal 7 with Omega 3

Despite I am giving advices of theming and design, I am not a designer, I am a developer, and the best I can do is to make something look good yet functional.
This tutorial is based solely on my experiences of Drupal 7 and Omega 3.
Requirements:
 
  • you should know some HTML basics.
  • you should know some CSS basics.
When it comes to Drupal subtheming, Omega is one of the best base themes, it is 100% configurable and HTML5 optimized, so, how is that we are supposed to theme Drupal with Omega, that is what we are going to discuss in this article.
 

Creating the subtheme

 
The very first step to theme with Omega is to create on of its subthemes, the best way to create a subtheme is using Drush and Omega tools, this can be made by typing this command.
  1. > drush omega-subtheme mysubtheme
Unfortunately, we will not discuss a thorough description about the subtheme creation in this article, however, you can find more information in the "Omega subtheming" section of the Omega documentation.
 
Once you create the subtheme and set it as default, you will see a bunch of odd blocks and pink lines, those are the sections being highlighted to show its spacing, width and height, in order to turn off that, simply uncheck the tiles at the right (temporary) or go to the options and turn off the debugging options (permanent).
 

Omega structure

 
Omega has a structure based on a grid divided in many parts; zones, regions and sections, this arrangement may vary depending on the modifications made in the .info file.
 
The regions are the smallest pieces of Omega structure, being more specific, they are the columns of the grids, they are supposed to hold the rest of the content (the blocks, Views, ...), the number of columns for each one can be configured, as well as the prefix and suffix (empty columns to fill unused spaces). The arrangement of the regions may change depending on the device (this can be configured in the options), you may expect that each region has its own margins (other properties such as "width" are also set), therefore, changing these properties via CSS for any reason is highly discouraged.
 
The zones are the containers of each grid, there will be as many grids as many zones are, the grids have a number of allowed columns up to 24 columns, each zone can have its own configuration, so maybe one zone has 12 columns and another has 16 columns, unlike regions, they take all the screen horizontally, and they can only be arranged vertically, the zones can only hold regions and nothing more.
MechDeveloper - Region demostration
The regions are the columns of Omega
Attribution: 
 
The sections are containers of the zones, their width takes all the screen and their height depends on the content that they hold, unlike the zones and regions, they can not be ordered (or even created) by the user, there are just three of them, the header section, the content section and the footer section, they must be considered as static content wrappers. For example, the header, content and footer sections should not be moved from their positions, if they were changed, the content may lose meaning or sense. There are no ways (at least in Omega) to create or arrange the sections, however, you can create more section by hacking Omega.
 

Overriding the templates

 
The method to override an existing template is exactly the same to the default way, the only thing to keep in mind is that the templates to override are in the "templates" folder of Omega, technically, Omega is a subtheme of Alpha (Omega is a group of Base themes, Alpha is just one of theme), therefore, all the templates are in the "templates" folder of Omega and Alpha, in order to override one of these templates, copy the template of the "templates" folder of Omega to the subtheme.
 
Omega provides templates to override each part of its structure (the zones, regions and sections), you may expect for each template a variable holding the content ($content), the content wrapper and the entity wrapper (in other words, another wrapper enclosing the given the zone, region or section), however, the sections will only have the content and its wrapper, Omega sets attributes to the content and entity wrapper in order to set required properties, for example, Omega adds CSS classes through this way to set the proper width to each region, therefore, modifying these attributes is highly discouraged.
 
When templating the regions, it is good to add or modify code only inside the entity wrapper, as it was said before, adding CSS properties such as margins, paddings or anything similar to the regions is highly discouraged, there are other properties that can break the layout as well, the border property is one of them, so the "box-sizing" property should be used along with it, remember that the regions represent the columns in the grid, their width and position can vary.
 
The zones have not the same restrictions as the regions, so you can add all the code needed wherever you want it to be, however, the content wrapper has CSS properties that should not be changed, the entity wrapper for all the zones may appear on certain conditions, any space outside the content wrapper can be used to specify a part in the webpage which its width takes all the screen. Let us see an example, this is the highlighted section of this website, as it can be seen, the highlighted sections takes all the screen from left to right, you can not do that with a region, the right approach to do so is to use the zone to take all the screen like that.
MechDeveloper - About me
This is the highlighted zone of this website, such parts like this can not be built using regions.
Attribution: 
 

Adding CSS

 
In order to give color to the website, the CSS files must be written, Omega provides some CSS files to implement the code to the theme, those files, as the rest of the theme, were built on the "Mobile First" methodology, this methodology is based on serving the design to mobile devices and then adapting it to devices with greater resolution, specially because a mobile device has fewer capabilities (by now) and smaller space than the desktop computers, adapting a mobile design which consumes lower resources to a desktop design which consumes higher resources is easier than doing the opposite.
Mobile First (Responsive Design)
The 'Mobile First' methodology is focused on delivering the website starting with the mobile devices.
 
The CSS files will be displayed in a specific order according to the screen size of the device accessing the website, starting with the file displayed for mobile devices, these files are described bellow.
  1. 0px - 740px: global.css
  2.  
  3. 741px - 979px: global.css + default.css + narrow.css
  4.  
  5. 980px - 1219px: global.css + default.css + narrow.css + normal.css
  6.  
  7. +1220px: global.css + default.css + narrow.css + normal.css + wide.css
All these files are described in the "Omega theory" section in the documentation of Omega, as it can be seen, each file has a starting device type where is being shown for the first time, from that device type, the file begins to be shown for the rest of the devices, according to this description, the "global.css" file is displayed all the time, this file must have all the colors, images, styles, animation, everything, this file must present the information for mobile devices, the other files will generate a backup/fallback for the other devices, formatting the existing arrangement to present the information as desired. Non-mobile devices such as tablets, laptops and PCs are shown starting from the "default.css" file, therefore, the "default.css" file is the proper file to add CSS code for the non-mobile devices.
You can place more CSS files as you like, for example, you may like to set another CSS files to make the website "print friendly", in order to do that just add some few lines to the ".info" file, like this.
  1. css[<the given CSS file>][name] = 'The name of the file'
  2.  
  3. css[<the given CSS file>][description] = 'the description of the given file.'
  4.  
  5. css[<the given CSS file>][options][weight] = '10 (apparent order of the file)'
  6.  
  7. css[<the given CSS file>][options][media] = print (print, screen, ...)
Every content wrapper and entity wrapper have a class and a specific ID with a common pattern (usually the class and the ID always are the same), this naming convention gives a way to refer to any part of the Omega structure in all the CSS files, the patterns for the regions, zones and sections are described as following; The content wrappers of the regions just have two classes, the first one is "region-inner" and the second one is "region" followed by the name of the region and "inner", everything separated with hyphens, the entity wrappers of the regions usually have "region" followed by the name of the given region separated with a hyphen. The content wrappers of the zones usually have "zone" followed by the name of the given zone, the entity wrappers of the zones usually have "zone" and the name of the given zone, but, additionally, it has "wrapper", everything is separated with hyphens (remember that the entity wrapper of the zones may not appear). The content wrappers of the sections always have "section" followed by the name of the given section separated with a hyphen.
This would be an example of all the patterns in the structure:
 
  1. <!-- this is a section -->
  2.  
  3. <div id="section-<section name>" class="section section-<section name>"> <!-- content wrapper -->
  4.  
  5. ... content ($content) ...
  6.  
  7. </div>
  8.  
  9. <!-- this is a zone -->
  10.  
  11. <div id="zone-<zone name>-wrapper" class="zone zone-<zone name>-wrapper"> <!-- entity wrapper, it may not appear -->
  12.  
  13. <div id="zone-<zone name>" class="zone zone-<zone name>"> <!-- content wrapper -->
  14.  
  15. ... content ($content) ...
  16.  
  17. </div>
  18.  
  19. </div>
  20.  
  21. <!-- this is a region -->
  22.  
  23. <div id="region-<region name>" class="region region-<region name>"> <!-- entity wrapper -->
  24.  
  25. <div class="region-inner region-<region name>-inner"> <!-- content wrapper -->
  26.  
  27. ... content ($content) ...
  28.  
  29. </div>
  30.  
  31. </div>
 
For more information you can visit "CSS IDs and Classes in an Omega theme: a general outline", additionally, the documentation of Omega also describes each part of the structure separately in the "Omega CSS Strategy Explained" section.
 

Layout arrangement

 
Unlike themes built from scratch, Omega allows to change the layout structure through the options of the theme, there is no need of programming skills to arrange the layout, when doing it, make sure you have completed all the customizations needed, Omega lets change the order of every zone or region. The structure of the website itself must be changed with these options, in other words, whether the logo is located at the left side of the header, whether it is in the center, whether there are three or four columns in the footer, all these things must be changed using these options.
Omega - Content arrangement
The layout can be arranged in the 'Zones and regions configuration' section in the options of the theme.
 
When arranging the layout you can set CSS classes to the regions, thus, defining all the styles that can be assigned to many elements as CSS classes is a good idea, try to pay special attention to this because the layout arrangement it is a key phase of Omega theming, besides, you would save a lot of time doing this and you would add extra functionality to the theme.
 

Gathering all together

 
Although we have seen almost everything what we have to know about Omega theming, all this information might be just theory, so we are going to see some practical guidelines and tips of how you should use it:
 
  • Before doing anything you should have an idea of the design that you are going to write down in the theme (just saying).
  • The common steps to theme with Omega are the following (or, at least, I would follow these steps); ( create a subtheme ) -> ( modify the HTML structure by overriding the templates if needed ) -> ( write the CSS files ) -> ( arrange the layout to make the theme look as planned ) -> ( blocks, views, writing content, ... )
  • The design of the website and the Omega structure must match somehow, the very first step to do this is defining all the zones and regions that you are going to use, the default regions and zones brought by default with Omega are handy, but, you must be sure that those are enough for you, if it is not, then define as many region and zones as you need. Make a good use of the Omega structure, the structure of Omega is good enough to handle any web page, it is really important to think about the possible zones and region of the design, you do not have to think about blocks or any other thing (by now), remember that the zones are the containers for the grids and the regions are the columns itself.
  • There are a couple of zones or regions that you are more likely to override, for example, the menu region and the branding region, those regions can be overridden to modify the content of those region in case that some options are activated such as the main & second menu, the slogan or the logo. Additionally, there are some design which require a zone pretty different of the other zones, the templates of these zones are candidates of being overridden, although Omega is HTML5 optimized, you can override the template of a region to set special semantics (aside, section, article, ...).
  • In order to make the theme layout look as the design, you must arrange the regions in the options of the subtheme, if the logo in the design is in the center then place the branding region in the middle of two region (that surely will have a divided menu), if the logo is at the right then arrange each region properly.
  • Once the zones and regions are arranged, set the blocks to its corresponding regions, all the regions will be shown in the blocks option of Drupal, in other words, this would represent to assign the content of the website.
  • All the sections are the background of the whole theme, make sure to set the proper colors and images for each section.
  • Try to make a proper use of the CSS classes, you can use CSS classes to assign the styles to the regions, some other modules such as Panels and Views can use this as well (even CKeditor can use CSS classes).
  • Use the naming pattern of Omega to give the proper look to all the desired parts of the layout using CSS, most of cases, the header, content and footer sections, along with the sidebar (first & second), branding and menu regions, are always customized.
  • Never use any property that can break the layout such as border, margins or paddings, this also includes position properties with "absolute" value ("position:absolute").
  • Most of cases, toggling off the unused stylesheets is encouraged, check if the theme really needs the "Menu styles", "Omega styles", and any other stylesheet, this can be found in the "toggle styles" section in the options of the theme.
  • Unfortunately, you must set the conditional HTML tags by yourself because this does not come with Omega, simply replace the HTML template (html.tpl.php), remove the current HTML tag and add the conditional HTML tags, this would be the example of a modified HTML template file.
  1. <?php print $doctype; ?>
  2.  
  3. <!-- add these lines bellow -->
  4. <!--[if lt IE 7 ]> <html lang="<?php print $language->language; ?>" dir="<?php print $language->dir; ?>"<?php print $rdf->version . $rdf->namespaces; ?> class="no-js ie ie6"><![endif]-->
  5. <!--[if IE 7 ]> <html lang="<?php print $language->language; ?>" dir="<?php print $language->dir; ?>"<?php print $rdf->version . $rdf->namespaces; ?> class="no-js ie ie7"> <![endif]-->
  6. <!--[if IE 8 ]> <html lang="<?php print $language->language; ?>" dir="<?php print $language->dir; ?>"<?php print $rdf->version . $rdf->namespaces; ?> class="no-js ie ie8"> <![endif]-->
  7. <!--[if IE 9 ]> <html lang="<?php print $language->language; ?>" dir="<?php print $language->dir; ?>"<?php print $rdf->version . $rdf->namespaces; ?> class="no-js ie ie9"> <![endif]-->
  8. <!--[if (gt IE 9)|!(IE)]><!--> <html lang="<?php print $language->language; ?>" dir="<?php print $language->dir; ?>"<?php print $rdf->version . $rdf->namespaces; ?> class="no-ie no-js"> <!--<![endif]-->
  9. <!-- add these lines above -->
  10.  
  11. <!-- remove or replace this line below -->
  12. <html lang="<?php print $language->language; ?>" dir="<?php print $language->dir; ?>"<?php print $rdf->version . $rdf->namespaces; ?>>
  13. <!-- remove or replace this line above -->
  14.  
  15. <head<?php print $rdf->profile; ?>>
  16. <?php print $head; ?>
  17. <title><?php print $head_title; ?></title>
  18. <?php print $styles; ?>
  19. <?php print $scripts; ?>
  20. <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
  21. </head>
  22. <body<?php print $attributes;?>>
  23. <div id="skip-link">
  24. <a href="#main-content" class="element-invisible element-focusable"><?php print t('Skip to main content'); ?></a>
  25. </div>
  26. <?php print $page_top; ?>
  27. <?php print $page; ?>
  28. <?php print $page_bottom; ?>
  29. </body>
  30. </html>

About me

About the author
Miguel Rodríguez is a freelance developer from Caracas - Venezuela. He is a persistent and goal-oriented person who tries to make the best use of the resources. He is positive, proactive and motivated enough to set a goal with the intention to fulfill it. Find more about him .