Drupal 7 Theming - How To Do Html5
In this blog post well be discussing about how to do HTML5 in Drupal 7
. Apart from HTML5, we will also cover how to remove some of the generated markup that Drupal provides by default, and how to override default system CSS. Well also look at a few tips on how to get some quick-win page speed boosts.
Before we probe in deeper, its good to mention that this post is not a comprehensive tutorial on building a Drupal 7 theme. For the sake of briefness, we wont be able to cover the HTML5 Tools module, which helps to add features like new HTML5 form elements to Drupal. Rather than that, we will focus on reducing the superfluous XHTML that Drupal still unconsciously wants to include, as an inheritance from its earlier stages.
Structure
At the time you first install Drupal, you will be able to see a top-level directory named themes. It is only apparent that youll be thinking that this is where you should store your own theme related files. However, in this case, this is wrong. Actually, the directory you want to play in is sites. This is all about you and your particular site, and within this is another themes directory that will be housing your themes.
It is important to note that Drupal can handle multiple domains via a single codebase, and thus, the sites directory instead of site, but we would not be discussing about it in detail, as it is beyond the scope of this article. To know more on this topic, then theres a Multisite Drupal group that is dedicated to the topic.
As a first step, the initial thing to do is to create a *.info file with the name of your theme. Since our site is Valuebound.com, and our theme is aptly named Valuebound, our info file is valuebound.info. the following are the contents (; comments out a line):
; BASIC SETTINGS
name = Valuebound
core = 7.x
; FEATURES (intentionally blank)
features[] =
; REGIONS
regions[front_journal] = front_journal
regions[content] = content
regions[sidebar_first] = sidebar_first
regions[sidebar_second] = sidebar_second
regions[search] = search
; CSS
stylesheets[all][] = assets/css/override/kill/ctools.css
stylesheets[all][] = assets/css/override/kill/field.css
stylesheets[all][] = assets/css/override/kill/node.css
stylesheets[all][] = assets/css/override/kill/system.messages.css
stylesheets[all][] = assets/css/override/kill/system.menus.css
stylesheets[all][] = assets/css/override/kill/user.css
stylesheets[all][] = assets/css/override/kill/views.css
stylesheets[all][] = assets/css/reset.css
stylesheets[all][] = assets/css/override/keep/system.base.css
stylesheets[all][] = assets/css/override/keep/system.theme.css
stylesheets[all][] = assets/css/override/keep/search.css
stylesheets[all][] = assets/css/960_12_col.css
stylesheets[all][] = assets/css/text.css
stylesheets[all][] = assets/css/formalize.css
stylesheets[all][] = assets/css/site.css
; JAVASCRIPT
scripts[] = assets/js/master.min.js
Aggregation
If you are familiar with the Drupal themes, then youd observe that the preceding code is pretty straightforward stuff, there nothing that is too extra-ordinary. Another thing, that you might have noticed is the override directory. Within it are two other directories, kill and keep.
We also learned a clever way to get rid of system CSS files that we dont want. If you name one of your own CSS files the same as one of the defaults, Drupal will include yours rather than providing its own. Thus, everything in the kill directory is just an empty file, whereas everything in the keep directory is a CSS file thats been only slightly or not modified from its original defaults.
So, its natural if you are wondering Why bother to have a keep directory at all, if Im reusing the very same code as the default files it contains? Heres where it starts to get interesting. When you go to the Performance admin page, and turn on aggregation and compression of CSS files, Drupal will gather up all its default system stylesheets into a single file, and all your stylesheets into another.
It may sound silly. But with our keep directory, we force those default stylesheets along with our theme stylesheets, to be aggregated and compressed into one file.
Template.php Section
One of our old practice from the early CMS days, which we havent given up is using Textpattern. This is because for theming purposes we like to know what section of the site we are on. Basically, that just means that were curious what foobar is equal to, in the following scenarios:
http://example.com/foobar
http://example.com/foobar?page=1
http://example.com/foobar/node/search%20term
Thus, at the beginning of our template.php file, we have a simple function that runs through and gets us the first path fragment in the URL, it does a simple switch/case, and returns a string that becomes the ID.
After HTML5
/* Code here. */
/* Code here. */
Template.php Minification
Although this doesnt actually apply to HTML5 directly, we decided that while we were mucking about in the template.php file, we might as well add some HTML minification. Essentially, the following code just strips out unnecessary whitespace and line breaks, saving a bit of file size wherever possible. If a page contains a or tag, it is left alone, as to not affect code blocks or text typed in a form.
// Minify HTML output.
function valuebound_process_html(&$vars) {
$before = array(
"/>ss+/",
"/ss++">
page.tpl.php
by: valuebound
Timeshare Closing Company Providing Escrow Agreement The Increase In Trend Of Swords With Sword Sale Hitachi Window Ac The Best Deal Ever Usa Made Cat Condos Role Of Town Planning Consultants Hindi Songs For Complete Peace Of Mind A Robust Transportation System Available For Your Belongings I Believe I Can Fly Reasons To Experience Fawlty Towers Dining Matrixyl: The Formula One For Restoring Youth Bookings Opened For Jaypee Greens Latest Project Jaypee Orchards How To Get Out Of Tax Debts? Tips To Choose Good Interstate Melbourne Removalists