Learning How To Theme in Drupal, Starting at Square One

06.22.2006

Note: I'm going to start regularly answering questions I get via email by blog. The reason being that email is a blackhole; and I am getting too many good questions everyday. When I have a few moments to answer, I figure I should make them available to everyone.

A reader by the name of Fouad writes:

Hi, I went through your tutorial on drupal themes, but it required a lot of programming experience. Isn't there an easier way to put together a drupal theme? For example, what if one wanted to start with an empty page, and build their theme from the groundup?

...is their a straight forward process to make 2 column/row, 3 column/row, 4 column/row themes?

Drupal themes are very straight forward... ...provided that you understand why they are straight forward, and why a more straight forward way is difficult (actually, impossible at present... that may change in Drupal 4.8 or 4.9).

Now, for the 99.999217 percent of the population that doesn't understand why drupal theming is straightf orward, I have bad news. You've got a lot of learning to do. In the beginning, the task of learning how to build a solid drupal theme is going to appear daunting, painful, confusing, sadistic, cruel, unusual, and most importantly, boring. I know these things because it wasn't long ago that I first started teaching myself HTML/CSS/PHP and began to learn how to apply it to drupal (November 2004). So forgive a LONG answer to a question that sought a short answer. Rest assured a short answer would have been a fairy tale.

In this post, I will attempt to provide those with little to no experience in web design a place to start. Let's begin with this overly simplistic but practical picture of what a drupal theme is:

Three Layers Written in Three Languages; Each with a Distinct Function

Drupal theming is an application of CSS/html/php programming. To ask "how can I learn theming without learning HTML, CSS and PHP?" is like asking, "How can I learn Jazz piano without learning how to play the piano?".

The human body serves as a metaphor for the parts of a drupal theme (my guess is that we all share that in common). Roughly speaking:

Layer 1: the Skeletal system. The HTML markup serves as the foundation for which the rest of theme depends. Without a basic understanding of HTML, you'll deprive your theme of a normal, and solid bone structure. You're theme will be deformed, weak, and probably collapse, and die at very young age. Clearly, this is a scenario that should be avoided altogether if possible. Start here, if you're just beginning.

Layer 2: the skin, and muscle. The CSS layer is more than merely "skin deep." Lots of stupid programmers think CSS is "not a real language", and is a skill best left to wimpy boys. "Real men", so the argument goes, only code in Java and Python.

This attitude always reveals itself in the ugly interfaces, and ugly, rigid markup their scripts generate. CSS is not only the path to beauty on the web, but it absolutely transforms the presentation of markup. It can make vertical menu trees turn into horizontal cascading tabs. You can markup two sidebars at the bottom of your HTML page, and squeeze them to sit nicely next to your center content. Its also the most artsy of programming languages (imho). In comparison with learning the HTML basics, and PHP syntax, CSS is by far the most immediately rewarding of them all.

Layer 3: PHP -- the nervous system, and heart. Without a brain, or a heart, what happens to people? They die, obviously. The same is true for your drupal theme. PHP is the layer which allows you to transform a dead layout into a live breathing page.

A "Quick" Sermon for Beginners

The best metaphor for learning how to build a drupal theme is learning how to play an instrument. If this introduction seems long, than I caution you: you have a long journey ahead of you. The truths about learning a new musical instrument are identical to the truths of learning how to theme for drupal. So, be forewarned:

  1. You must be motivated to learn by a passion, a dream, or a need to escape a present reality. Without that, you are unlikely to have the patience, and dillegence that is required to finally be able to "play for enjoyment".
  2. When you first start, its going to suck: its going to be both boring, and confusing. Can you endure the unpleasent experience of watching yourself suck, while both confused and bored?
  3. There are no shortcuts, YOU MUST LEARN THE FOUNDATIONS. Anything you perceive as a shortcut is going to cost you more time in the future, than just learning it the right way now.
  4. The single biggest barrier between your present reality, and your future goal is practice, practice, practice.
  5. Its going to take time. And it takes time for everyone. Go easy on yourself, don't expect yourself to grasp CSS floats in an hours time.
  6. Like anything worth doing -- getting there requires sacrifice that most people won't be willing to give.
  7. Even when you get to my level, you will still remain deeply unsatisfied with your present skill and knowledge. And that in itself becomes a great reward in the end.

This is just the honest truth. Its 2006, and building things on the internet is still an occult art. That is why so few people can do it well. If it were easy, and straight forward, than -- there wouldn't be so many terrible web pages.

Everyone begins with no clue as to what they are doing -- I coded my first HTML tag in the summer of 2004. My knowledge has been entirely gained from a rigorous program of aimless experiementations, disasters, and the lessons I've learned from them.

Trial and error is not merely the best way to learn -- its the only way. Luckily, you can at the jumpstart your process by learning from web designers all over the web. And, web designers love teaching.

WHERE TO TAKE YOUR FIRST STEPS

I took some time to gather the best, most readable, humorous, and free materials to help you start. Take note of the sources in this list. I've made it a point to only select the best of the best sites on web design. It is far from an exaggeration to say that not one web professional is unfamiliar with these sources.

I will divide these materials into "movements" -- merely for the fact that its a musical metaphor that can also be interpreted as a gastrointestinal metaphor. The truth indeed lies in between the two. And I'm werid.

Movement 1: XHTML Crash Course.

Forward

Back to the Basics (alistapart.com, 2001) Do read, web design is as much about philosophy as it is code.

"When you hit a fork in the road, take it." - Yogi Berra

1. Site Point: XHTML Web Design for Beginners part 2

Note that we are starting with part 2 because part 1 is theory that you don't need to worry about yet... or, come to think of it, ever. If you find yourself lost in this tutorial, try this tutorial instead: Sitepoint: The Absolute Beginners Guide to XHTML/CSS'

2. (Alistapart.com): Using XHTML/CSS for Search Engine OptimizationBelieve it or not, the quality of your markup directly affects your sites traffic. See, learning the basics IS practical!

3. (456 Berea St.) Attributes Vs. Tags Vs. Selectors So you can start to sound smart while talking about code :-)

Conclusion of Movement 1:

(456 Berea St.) Top 10 Reasons to Use Web Standards

Movement 2: On Scratching the Surface of CSS

Forward: (A List Apart): The Tao of Web Design

The Great Introductory CSS Tri-tutorial

Selectutorial -- Selectors are one of the most important aspects of CSS as they are used to "select" elements on an HTML page so that they can be styled.

Listutorial -- the basics of building background image lists, rollover lists, nested lists and horizontal lists.

Floatutorial -- the basics of floating elements such as images, drop caps, next and back buttons, image galleries, inline lists and multi-column layouts.

The Myriads

 

1. (A List Apart) In Search of the Holy Grail Note, the "holy grail" is an inside joke regarding 3 column css layouts. See this old hag for more more background on the joke. I swear its funny if you had one time thought the hag was "the holy grail".

2. (Juicy Studio) Div-Mania! More and more web documents are appearing that consist of nothing more than a collection of div elements. In most cases, better use of CSS selectors could be used to avoid overusing the div element.

3. (huddletogether)Squeaky Clean CSS Tips on how to code CSS without making your life a living hell.

4. (BarelyFitz) Learn CSS Positioning in 10 Steps I wish every CSS tutorial was like this one. Oh, I forgot to mention: in css, position is everything.

Attention Shoppers: the blogger needs to get up early tomorrow and its 1:37 in the AM.

I feel no regrets, this is plenty of material to get the intended audience through a full week. Nevertheless, I'll finish this tomorrow evening. If you read me via RSS, I'll post a notice. I'm sure this list will change a lot as time passes... As it turns out, reviewing and reading material for quality is time consuming.

Comments

buy wow gold cheap wow power

thanks.

thanks.

This attitude always reveals

This attitude always reveals itself in the ugly interfaces, and ugly, rigid markup their scripts generate. It is obvious I must say.
order thesis | order research paper

In our last review of WYSIWYG

In our last review of WYSIWYG editors, a certain editor won because it met my low expectations. Thanks to the tip from Sanjeev, I found an editor so good its off the charts.

Thesis Help AND Buy Assignment

. I know these things because

. I know these things because it wasn't long ago that I first started teaching myself HTML/CSS/PHP and began to learn how to apply it to drupal (November 2004). So forgive a LONG answer to a question that sought a short answer. Rest assured a short answer would have been a fairy tale.
Dissertation Writing AND Law Thesis AND Business Thesis

Nick, I am actually trying

Nick,

I am actually trying to staff a position with a Drupal Theme developer! I have found your blog most helpful. Any chance you would be open to an opportunity here in Chicago, IL?

nford@kforce.com

THANKS!!

hi i am having a rather

hi i am having a rather annoying problem. I got druple up and working fine i then had some problems with the themse so i tried to install them. In the end i installed a fresh copy. The problem is now when i try and enter my details for the database name and the server which in my case is localhost. All that happens is the screen refreshes but nothing happens. Can you explain how i can fix this since i have already tried reinstalling druple version 6. Should I uninstall WAMP. Please advise.

A big part of Open Source

A big part of Open Source Software (OSS) is about collaboration and modular enhancement of the core product. Drupal's modules are a prime example of this concept. Do CMS end users debug and improve existing modules or do they write their own modules? As modules are improved and enhanced will there ever be a stage when implementers will hardly need to write code. This survey is being conducted to determine how much code Drupal implementers actually need to write. The advent of modules such as CCK, Views, Organic Groups, Workflow, Ubercart, E-Commerce, Panels and Actions along with a dozen or so other modules has a empowered web developers with the ability to create sites writing little or no custom code. Is this true? If you are Drupal user please take the survey at http://www.mahalasoft.co.za

i use to use

i use to use "_phptemplate_variables" in drupal 5, can you please write a simple example of "template_preprocess" in drupal 6. i want to give different theme to certain pages in my site and just cant do it.
thx in advance.

migrating to drupal

I have built a bunch of client websites using wordpress as my back end cms and am wondering if anyone can tell me how the learning curve of wordpress stacks up against the learning curve for drupal? Wordpress is relatively pain free but has several areas where it's functionality as a full fledged cms are limited. Drupal seems much more robust, but I wonder about how theming it stacks up vs wp.

Drupal theming for designers

Designers interested in getting up to speed on creating Drupal themes may also be interested in Drupal theming for designers

Great post

Just found this post. It's just what I needed to hear... I just have to bite the bullet, but this has given me encouragement to just power through it. I had never written a line of code in HTML before April 2007. Now I know a bit of CSS, and I have been reading the Sitepoint book on PHP/MySQL to get started on that end... then hopefully I will be able to slowly get into Drupal.

Thanks!

what you say is really the truth.

i like the "A "Quick" Sermon for Beginners" part of this article! its really encouraging thoughts! thanks. im beginner to drupal and i think what you say is really the truth.

Thanks.

Muito bom o artigo

Estava procurando algo parecido no google, e encontrei este post no blog, muito bom, me ajudou a terminar o site Orolix.

Simple way to make a Drupal theme

You can make a first Drupal theme by copying Bluemarine from /themes to /sites/all/themes. Then open up page.tpl.php in an editor. Strip out all the HTML tags and just leave the PHP snippets. Those PHP snippets print variables that contain the content. You can find out what each variable means on the PHPtemplate variables page. Add your own HTML to replace the HTML that you removed. Edit style.css to your liking. node.tpl.php themes the nodes and comment.tpl.php themes the comments.

I also recommend reading Chapter 8 of the book Pro Drupal Development

Very helpful BLOG

keep up the good work men! I agree with you! need to have a background on html and css in order to have a good grasp in working with drupal and a basic php knowledge. We started using Drupal and we agree its far better than other CMS out there. And thanks for making this article available to the public. Hooray to the opensource community. Knowledge is free but use it for the good of human kind. kudos to you!

found it

Great inro.
But where do I write and test PHP code?

I'm hosted by Bluehost and have Drupal 5.1 running there.

I need a test (learning) environment to play around, I guess something like what a wikipedia sandbox is.

I an sure I can find something, but I can only be rasonalby comfortable (sure that it fits) if someone like you suggests it. I'm going to look aaround now to see how much Dreamweaver cost and what it does(???).

You can use WAMP (Windows

You can use WAMP (Windows Apache MySQL PHP) and install a local server on your computer as a testing environment for your PHP code. If you have a Mac, you can use MAMP (same thing, but for Macs). Try Googling "wamp" or "mamp" to find whichever you need. I am new to Drupal and installed WAMP, which is free, not long ago, and have started using it to check my PHP code.

Waiting for more to come...

Great start. I got the HTML & CSS stuff down cold. Please hook us up the the PHP basics needed to skin a drupal site!

Thanks in advance.
David Martinez

there must be an easier way

there must be an easier way to theme drupal without knowing php etc. for example i havn't even looked at what is in the chunk of code you add to joomla's template but what i care about is the placement of and so on zones and the CSS. that what most people are asking about. anywayi appreciate the effords you do.

easier way

If this way (making your theme from "zero"), you could try to modify existing theme.

Good one to modify (with just changing css) is Drupal Zen Theme.
One of the "mods" is Drupal Bluebreeze Theme.

Many thanks Nick

I'm really delighted that you have take the time to post up the page http://www.nicklewis.org/node/850.

Please ignore idiots who need a quick fix to theming. I donated a few dollars in recognition of your effort - because I know what you have written is good stuff.

Drupal is still very much misunderstood and there will always be impatient souls looking for theming to happen like instantly.

I wish to encourage you to ignore unappreciative comment. Please continue to update the page ever so often. Many newbies will benefit.

Just what I was looking for. Thanks!

Thanks for this. This is exactly what I was looking for. Hopefully by the time I get through all your suggestions I will be able to at least ask educated questions when it comes to this. I have installed both Joomla and Drupal 5.1 and like the Drupal back end better. The only issue is that there are a lot more templates for Joomla so for any near future project I will have to go with that platform and just change around the template a bit. I wish I had more skill, hopefully soon.

useless

sorry but this site is useless, if i wanted someone to tell me to go learn html , css and php , that can be written in one sentence.

what i was looking for when i came here was what the title says, learning how to theme in drupal, starting at square one, however, this site didn't teach me anything related to themes in drupal.

Good theming introduction for non-designer people

I think that this article actually covers subjects skipped in tutorials on drupal.org.
It is good orientation article with quality pointers how to start the Drupal theming when you have not done web design previously.
If you are seasoned web designer going Drupal, you don't need this article. Others will find it useful.

You won't be able to write a

You won't be able to write a drupal theme until you get html, and css basics down first. Once you understand html, and css, than theming is going to make a lot more sense. And, you won't be overwhelming yourself with trying to learn html,css,mysql, and php all in one go. Start slow, get html down first, css second, than php, than mysql.

If you are starting a square one, that's just how it is. Sorry.

gone are the days of

gone are the days of actually learning what you need to get results..., thought this post made a lot of sense. If you want to be able to make beautiful things, you need to put the work in. If everyone could do it just like that, then beautiful would become standard and cease to be beautiful anymore...

Great article, thanks for sharing your wisdom.

Wicked

I'm new to drupal and find your site a brillant start. Like everyone above, I'm keen to get my little head around the idea PHP. Thanks.

Waiting with baited breath

I know the HTML / CSS side ... it's the php part that has me completely frustrated. It may be necessary to Drupal but all I want to do is make it look better than it does. Please hurry... thanks.

give us the nervous system!

I'm sure it's somewhere on your site, given you wrote Part I in June... I'm a Mambo/Joomla web designer who is learning the Drupal ropes - with Mambo/Joomla, all I need to know is HTML / CSS in order to drastically modify the template; it appears that I need a crash course in PHP in order to do anything significant in Drupal (a point against it, in my designer's opinion). So - the PHP crash course - any leads would be great. merci, merci babs

I swear — I will — soon.

I swear -- I will -- soon. I'm very swamped -- its not that I'm lazy -- its that there are times where I have to find balance between my natural propensity towards thrusting my weird code-tutorial-riff-thingys upon the general public, and meeting my day to day responsibilites (which have reached a satirical intensity, as of late). 

You say that that you only need to know HTML/CSS with Joomla.

Well... I applaud your sensibility, and good sense in not attempting to go further in Joomla. Because frankly -- when you have to change Joomla's dynamic content's presentation -- life is not worth living -- and one would be better off fleeing to the jungle. 

The jungle is full of delicious nuts and berries, I might add.

Thank you so much!

Feel like I've been beating my head against Drupal for ages. I'm so grateful that you're going to do more of this.

Looking forward to the nervous system!

Is movement 3 forthcoming?? I'm a developer/designer, so I'm pretty comfortable with html/css. But I'm relatively new to Drupal, and completely new to php. Your article looks great so far but I'm really holding my breath for that next section!

Thanks for the reference material on drupal themes

You speak sooth. What are your feelings on the conception of the design itself? Do you think it progresses from a mastery of the underlying language skills or is a third force that must be considered? I find myself now, with my knowledge of css, php and html looking at pages - thinking - I could have done that, but never seem too. I feel like I'm going through a stage in the process. Anyways - I'm hoping to theme up my drupal site - the learning is the most time consuming part of the whole exercise. GS

php

best way to approach PHP?

PHP Tutorials

Good ones on Lynda.com and Sitepoint for purchase. W3Schools has free tutorials...

Email form

The email form spits out a "validation" error when trying to email you from it. Both logged in, or out.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.