theming

The theming firehose (NB for designers & front-end developers new to Drupal)

Drupal markup in a Wordle

You theme with the mark-up you have, not the mark-up you'd like to have.

That's the essential truth that designers and front-end developers new to Drupal need to understand. You don't get to construct your pages from scratch, building out essentials, never a wasted div, never an extraneous class. No, you have to flip the entire process around. With Drupal you're getting markup shot at you from a firehose, and as a themer you need to sop it all up and make it pretty. Don't spill a drop.

What this means is that, by default, you're spending a lot of time debugging the theme you're building so that it handles all the different configurations, content types, page structures, etc. that the Drupal site is throwing at you.

You have to be braced for it. It can be overwhelming. You can feel like you're drowning. Don't worry. You'll get used to it after a few months. Mostly.

Make friends with Firebug.

But wait, can't this situation be changed?

Well, kind of. You can intervene in the mark-up. You can write your own page templates. Your own fields templates. Your own views templates. Your own search templates. Your own node templates. Your own comment templates. But be warned: You're going to be working against a ton of mark-up. And you'll need to know some PHP to add your own variables — mighty powerful and nifty, but your Dreamweaver chops aren't going to help much.

You see, Drupal aims to be flexible, and it does that by throwing a zillion divs, spans and classes into the output. That means if you're not expert at CSS, you're going to be lost adrift in a sea of markup, and if you are expert at CSS, you have to learn how to see through the clutter — because when you have four or five nested divs to contain one single element, it's not necessarily obvious which one to target with your CSS. Especially if there's some nefarious Drupal core CSS already at work.

There are endeavors to make Drupal mark-up better, including in the HTML5 Initiative. But that's a slow process, and it sometimes meets heavy resistance.

Meanwhile, to get sites themed now, you may have to change how you work. Change how you view the web “page”. Get used to being the html sponge, absorbing and directing the firehose, using only the drops you want and letting the rest by without touching a thing. Let go of the idea that you're building from scratch, and get used to the mindset of diagnosing what's already there.

That's the price of power. Drupal is incredibly powerful. You need to flex your theming muscles to match what Drupal throws at you. Work through the complexity. Trust in Firebug. And don't despair. In the end, the resulting webapp is orders of magnitude bigger and badder and more kick-ass than what you could have done on your own, having 100% control but going it alone.

Is the site logo content?

Is the site logo content?

A brief exchange on Twitter with Jen Simmons (@jensimmons) and Morten Heide (@mortendk) about how to best incorporate a site logo into a Drupal theme got me cogitating on this question. Jen tweeted:

...What should go is the habit of hardcoding content into the theme. #separationplease #drupalwtf

@jensimmons

"Content"? Hmmm. This got me pondering: Is a logo "content" per se? My immediate response was in the negative. But upon further consideration, I don't think it's all that clear cut; I'm definitely less certain today than I was yesterday.

This post is a bit of thinking out loud on this question. Comments welcome! (But no need to shout #wtf, okay?)

Content or architecture

To me, "content" in a Drupal site is the content, as in nodes, comments, image uploads, embeds, etc. The content is the information. Come back to an article on kitten care a year from now and the content will be the same (or at least it should be).

The logo, on the other hand, is a graphic component of the user interface as well as the branding. The logo is the visual representation of the site identity. It may change and evolve, as logos do, as user interfaces do.

But functionally the logo in the web application is really a part of the site's architecture. The logo is "home." Redesign the site, revamp the logo, change its colors, replace it altogether — it is still "home" in terms of the functionality of the application. In that sense, it is fundamental architecture.

When planning, designing and developing a custom website, the theme is custom, a part of the entire design that includes architecture. (At least, this is the assumption I'm working from.) One typically does not move a logo around on a page willy nilly. One typically does not swap out the logo for another — not unless you're also changing the theme as well, as part of an entire redesign. The logo is a part of the whole user interface, the whole user experience, the whole compositional balance of the page. Conceptually it's hard for me to split out the logo as represented on the page itself as somehow apart. Logos have their own separate life, yes, but in a user interface context matters. One might even argue that the entire user interface is all a part of the branding, with the logo just playing one part. One might....

One of the advantages of a Drupal site is that a site administrator can actually manipulate the site architecture without touching code. This helps site building happen much quicker than it would otherwise. This admin control over architecture also can be handy for site owners, even if used only once or twice in a year. And it constitutes configuration stored in the database.

But does that make architecture "content"?

Drupal is very good at blurring the lines between functionality and presentation because of this paradigm. In puritanical (small "p") terms, it's undesirable, this blurring the lines. But in terms of usability and convenience for site owners, it ends up being empowering. Site menus can be modified, added to, deleted from. Blocks can be repositioned. The user interface, in other words, ends up being extremely malleable and subject to the whims of any user with the appropriate administrative permissions.

But is it content? I guess it depends upon what you mean by content. In terms of interaction design, I tend to view the site logo as a component of the entire user interface design, as part of the architecture in terms of functionality.

In Drupal, by default the logo can be uploaded from within the Drupal admin interface, and in that regard it's something like the other architectural elements that are exposed in the Drupal back-end. But the logo's purpose is locked in Drupal core. It links to the website "home page." The administrative control of the logo is restricted to determining what graphic will be presented as the logo. In other words, the logo ends up being merely the visible face of core Drupal functionality, the site architecture.

However, in terms of design, the logo is ideally integrated in the entire page design, and ideally is not simply a drop-in graphic, swappable at a whim. What's more, how that logo appears — i.e., what that logo's graphic image might be — depends upon the site design, which in turn is greatly affected by the device for which the theme implementation is intended. For example, if handheld compatibility is being addressed, the logo on a site viewed in a desktop browser will almost certainly be different from the logo used for users viewing on a handheld device. This makes Drupal core's logo upload functionality too limited and requiring either alteration or bypassing, because when the logo is uploaded into Drupal, you just get the one logo per theme. To swap out the logo for different platforms and devices, you'll need to do some fancy theme coding to load a different image (not easy for most), use simple CSS to force-resize the image (not considered best practice), or load a completely different theme (which is often not desired).

One way to avoid this is to skip Drupal's logo upload paradigm and load the logo's graphic as a background image. This way the logo can be easily swapped through use of @media queries in CSS for different sizes and aspect ratios, to complement responsive theming for tablets and handhelds. Incorporating site logos into web design via background images using CSS is a common practice for many web designers and developers. It certainly makes it easy to do things like :hover states and other user-feedback goodness.

But maybe that's not the best approach. For one thing, it clearly treats the logo graphic as not content. What if it is?

In terms semantic

There's some interesting debate on this.

Keith on Shubox ponders the question, considers the possibility that the site logo can be considered content. He argues that for SEO reasons a logo loaded as an image can have an alt value. This doesn't convince me because the link tag that can be displayed with a background image (the logo itself) can have alt values, too.

Stack Overflow bats around the question with some very nice discussion.

One assertion that comes up is that the logo is content semantically. Again here I'm not entirely convinced — not when it comes to interaction design (for the reasons I describe above). However, I do see the site name, which may or may not even be printed on the visible page, as semantically critical. But the logo? Not necessarily. In many ways, the semantic web is not much interested in graphic logos, but rather the identities the logos represent. —Especially if you consider that logo on the same site at the same URL may be different depending upon the device you're viewing it with.

Still, the Stack Overflow discussion and other Google hits leave me questioning my assumptions. (Oh, and Google itself loads its logo in an <img> tag as content.) I'm open to convincing on this score. However...

In terms practical

In another tweet in our brief exchange, Jen noted that if the logo is loaded on a website as a background image, "nothing will print."

#facepalm

It's a good point: A logo set as a background image will not print if the browser is not set to print background images, and there's no guarantee that it will. And whether you offer printer-friendly alternative pages or try to remedy the matter in print.css, it's a challenge that wild and wooly browser-world does not make easy to solve.

In other words, the background-image approach for logo placement may well serve easy adaptability to a wide variety of devices, platforms and resolutions, it risks a #fail when it comes to presenting the logo on dead trees.

(And if the logo is missing, it will be missed, which again raises the notion that logos may indeed be content after all.)

So in terms of Drupal theming, maybe the logo refrain is: don't worry, print $logo, be happy.

My DrupalCon San Fransciso session: Grok Drupal (7) Theming

Drupal theming is incredibly powerful, flexible, dynamic and granular, but it can be a bit of a challenge to understand without knowing the fundamentals.

The Way Drupal Theming Was

When I started Drupal theming in 2004, it was all a bit overwhelming. Back then, the core theme engine was something called Xtemplate, and it gave the impression to the n00b themer of being a great big mess. When you looked at the page template, it was one big blob of markup and logic, and it was very hard to figure out to change just about anything. What's more, it seemed to be very brittle: change something and you got the white screen of death.

And thus life was for the themer through Drupal 4.5 and the beginnings of 4.6.

New Drupal Theming Power

Then, in 2005, came the PHPTemplate theme engine, thanks to Adrian Rossouw (now with Development Seed), and the heavens opened up.

Suddenly (well, not suddenly, as it took a lot of work) Drupal templating had a structural logic: a nested system that simplified the clutter, gave us defined variables to work with, and provided the basis for extending the system. This was really really cool — so cool that it immediately became the theme engine of choise, and, with Drupal 4.7, it became the theme engine for Drupal core.

I was so excited about it, I did my first Drupal conference presentation on it, at OSCMS 2007 at the Yahoo! campus in Sunnyvale. (It was part of a larger topic of overriding display upon which I collaborated with Greg Knaddison and Ezra Barnett Gildesgame, now of Growing Venture Solutions. The PDF of my slides are available here, though they're pretty outdated now.)

Since then the Drupal theming system has evolved and improved. There are a lot of nifty techniques, tricks, best practices that are available to the themer. What's essential is having a good understanding of the underlying architecture, because that's how you can figure out where to look, how to go about making the changes you want to make the theme yours.

No PHP knowledge is required ... beyond knowing not to muck with what's between the <?PHP ... ?> tags. Of course, knowing some PHP can help. But you can also pick up the basics as you go, if you want to delve into the coded bits.

Learning Drupal Theming in 2010

My session proposed for DrupalCon SF on Drupal theming basics brings a comprehensive look at the Drupal theming system and how the front-end developer new to Drupal can take charge of the output by taking advantage of what Drupal gives you.

You won't come out an expert — that would be a ridiculous promise — but you will come out able to start rocking your own themes. You will have a solid understanding how the Drupal theme is structured, how the various templates work together, how to define regions, how to add your own targeted CSS files and scripts, use of subthemes, some good base themes to work from, how to do custom overrides of obscure, quirky or persnickety output using preprocess ... and you'll grok theming in such a way that even if you don't know how to do something, you'll know how to go about figuring it out, where to look, what to change, etc.

And because we're about to enter the age of Drupal 7, this presentation will be about these things for Drupal 7 (with some notes on how things have changed from Drupal 6). So this session could also be of interest to the experienced Drupal themer who hasn't had a chance to delve much into Drupal 7 yet.

Session voting is now open for DrupalCon SF, so if you think this session sounds helpful to you, or would be of use to the several hundred people new to Drupal who are expected to attend, please vote for my session, "Grok Drupal (7) Theming".

Thanks!