Skip to content

Drupal Blog

Better Dropdown Menus for Drupal

I'm working on a new framework for dropdown menus and I'm running out of ideas. So far I got:

  1. Animation on showing as well as hiding the menu (superfish only supports on-show)
  2. Automatic configurable multi-column dropdowns. When number of items in a submenu exceeds set number a submenu is 2 columns, or 3 columns. (will look like http://www.whitehouse.gov)
  3. Added support for custom easing, including the additional easing from the jQuery easing plugin and some homebrew easing*.
  4. Animated properties are configurable (widh/height/opacity)

So what cool menu feature would you like to have on your next Drupal site? drop your idea in the comments!

*my new and favorite dropdown easing:

  easeInOvershootTurbo: function (x, t, b, c, d, s) {
    if (s == undefined) s = 1.70158;
    return c*(t/=d)*t*t*((s+1)*t - s) + b;
  },
  easeOutOvershootTurbo: function (x, t, b, c, d, s) {
    if (s == undefined) s = 1.70158;
    return c*((t=t/d-1)*t*t*((s+1)*t + s) + 1) + b;
  }

Mega Drop-down in Drupal, is it doable in Seven?

I love the look and feel of mega drop-down menus, but the Drupal menu system does not have an interface that facilitates grouping of links within menus, and it's even more difficult to throw HMTL into the menu that isn't part of the list of links.

Want your theme to be compatible with Context module? Better check your theme_blocks

I got a bug report for the Syan theme today about problems with openpublish - all the blocks were gone.

I hadn't tried openpublish before so I decided to check it out. Wow! A 10 megabyte Drupal distribution, including well over a hundred contrib modules. Furthermore, this distribution bypasses the Drupal block system and uses the Context module instead.

After deleting some fix in my theme's code I discovered that theme_blocks was the culprit. I checked the Context module code and found that Context was overriding theme_blocks! It uses this to output block content through it's own system, unfortunately there appears no other way to hook into the block content other than using the theme function.

If you want your theme to be compatible with the theme_blocks function in your theme, you're going to have to add some code, as commented by the Context developer yhahn in context.core.inc:

// Reroute theme_blocks() through context_blocks to determine block
// visibility by context. Only override theme_blocks() if a theme
// has not overridden it. It is the responsibility of any themes
// implementing theme_blocks() to take advantage of context block
// visibility on their own.

Thus if your theme overrides theme_blocks you're going to have something like this:

Forcing a theme onto the theme settings form

Ok admittedly most developers will never have to use this trick, but if you ever use color module, or any advanced customization through the theme settings API you will want to do some theming on the theme settings page!

My premium drupal themes in fact do a lot of things with the theme settings form, to name a few:

  • Override the color module stuff to modify the color palette
  • Add a bunch of jQuery scripts to enable live preview of color and layout settings (including a cool animation that resizes the container to any fixed or fluid width)
  • Adding stuff to the form that just needs custom styling, like the Cufon fonts overview

A trend is is recently gaining popularity is the admin theme. There are some great admin themes out there, but unfortunately the admin theme will also load on the theme settings page and spoil the configuration features. In Drupal 7, an admin theme is actually standard, so I was worried I was going to have to write a module to force the theme onto the theme settings page, and I think a theme that requires a module to function is not very elegant, neither is it convenient.

Solution

What do you want to see in Drupal Themes in 2010

Lots of interesting stuff has happened to theming Drupal Theming in 2009. The emergence of various theme shops, a pack of new basethemes, and a big improvement in the overall quality of the themes.

Drupal themes are getting better and it looks like this is an ongoing process. Just a few years ago everyone complained that Drupal themes were boring and all looked the same… Joomla and Wordpress were thought to have much better designs available.

From the support emails I get from my premium themes product line I’ve heard from many clients that they’ve switched from Joomla to Drupal because they finally found a theme that matched their needs, so for some users the quality of themes can be a factor of paramount importance for their CMS choice.

The Drupal project is growing fast as well and there is an upward trend in popularity of distributions, how will this affect theming? Are themes modular and flexible enough to play nice with distributions, or do distributions just need dedicated themes?

2010 brings many changes and I wonder how the theming landscape will evolve. Already I see that themes are getting more and more complex, almost turning into theme engines by themselves. This is not necessarily a bad thing but where will it end, I guess the best thing to do is try and get all these new theme features in Drupal 8 core!

What do you think will happen, or need to happen for Drupal themes in 2010?

Does spam thrive during economic decline?

Are laid off IT workers discovering that sending spam is easier than getting a job these days? It sure seems that way, even with mollom running on all forms around a hundred spam comments get through every week, and they seem to get more clever every time.

I just found the following comment below my review of the Drupal 6 Javascript and jQuery book:

Submitted by san diego real estate (not verified) on Wed, 10/21/2009 - 18:55.
The only reason why I like this book is that this book developers deep into the usage of jQuery in themes and modules and there is interesting stuff in there for developers of any experience.

I can understand mollom didn't get that message because even I thought it was a real comment. I was much surprised to

Why Drupal doesn’t have great themes -yet-

I think that both Todd and Morten have raised some very good points about difficulties with the theming landscape in the Drupal world, but I would like to offer my take on the issue.
First I will put on my economical hat and later on I will add some points from a developer point of view.

Product Life Cycle:

In the Joomla templates and Wordpress themes business, theme developers have already gone through all the stages that us Drupal folks will have to face in the near future. Premium Theme developers in Wordpress and Joomla appear to have gone through the classical Growth-Slump-Maturity pattern:
product life cycle for premium themes brands

I think the Primary reason why people currently stay away from doing premium Drupal themes is simply because if you want to offer premium value you need to bring some seriously good themes to the table. These themes take much work to develop, building a theme that works on thousands of different websites is much harder than to make a theme for 1 client. On my latest premium theme I spent about 200 hours developing it and developing all its extra features. And that was after about 2 weeks of work on the design, and with the ease and efficiency of having my own basetheme.
The thing is, with the current size of the Drupal themes market, I’m not going to make a profit any time soon!
The markets for Wordpress and Joomla are each approximately 10 times bigger:
product life cycle for premium themes brands

Steph & Chris from topnotchthemes.com and I, are pioneers in this field. It’s much easier and often more profitable to be an early follower, when Drupal themes and Drupal itself get a growth surge. When will this happen? No one can tell, it’s a risky business. I’m personally betting on Drupal 7 to make a difference.

Joomla and Wordpress are simpler to theme

Maybe the difference is smaller since the release of Joomla 1.5, but in the past there really wasn´t much you can do in a Joomla template, that´s why template was probably a more appropriate name. It´s just an html file where you could drop some variables. Same goes for wordpress.
In Drupal it´s a whole different story, there is a formidable learning curve. Especially if you want to keep up with the latest developments, your themes are not just a bunch of HTML files with some variables. In drupal we have theme function overrides, preprocess functions, Skinr, theme settings, Forms API, color module, the theme registry etc.etc.
If you want to compete in the Drupal premium themes business there is a lot more to learn than in the Wordpress world for example.

What´s next?

Cufon your Drupal Theme in 4 Steps

I love Cufon. It's easy, lightweight and fast. Cufon is scripts that embeds external font files in your webpage and it's gaining popularity rapidly. I see more and more implementations it mostly it just looks impressive. The headings on this site are also Cufon.

Heads up: you can familiarize yourself with Cufon+Drupal without doing the work, by downloading the Free alldrupalthemes.com basetheme.

Step 1: Downloading the Cufon package

You can download the minified version free of charge. We're going to load and implement Cufon through the theming layer, so download to your theme folder.

Step 2: Get yourself a Cufon font

Making fonts for Cufon is easy, you can take any TrueType or OpenType font and upload it to the Cufon Generator. This is what I love about Cufon, the generator tool does not only allow for easy conversion of the font, but also for optimization. With a few mouse clicks, you can select a subset of characters that you want to use in the font, and if you're still not happy with the filesize you can optimize the paths.

Filesize can differ hugely between fonts. Some fonts can look great and weigh only about 15kb, but more complex fonts can easily get to around 1000kb!. The key factor is the amount of paths in the letters. Normal lettering has just a handful of paths in each letters, but it's the fancy fonts you have to look out for, such as these:

They may look great, but is it worth the large download time and resulting flicker that may occur during reading.

Download the .js file from the generator to your theme folder.

Step 3: Invoking Cufon

The Cufon script doesn't do anything by itself, you need to tell it where to go. Thankfully, Cufon integrates with jQuery, and you can use a jQuery selector to steer Cufon to your headings. If you just want to replace all headings, your invocation script would look like this:

Cufon.replace('h1, h2, h3, h4, h5, h6');

In my premium drupal themes I use a more elaborate invocation:

Cufon.replace('h1#sitename a,.nodetitle a, #navbar > ul > li > a', { hover: true }); Cufon.replace('h1, h2, h3, h4, h5, h6, p.mission, p.slogan, .views-field-title, legend:not(.collapse-processed)');

Firstly, there is a separate selector for links. They get a separate invocation with the hover option set to true, so that the hover styles get properly processed by Cufon. It says in the documentation that Cufon is slower with hover set to true, so you may not want to use it on all your headings.
Secondly, there is a big selector that targets all other headings, as well as some Drupal native styles such as the mission, slogan, and views headings. The last bit might strie you as odd, it's a CSS3 style jQuery selector that targets all form fieldset legends except for the ones that use the Drupal native fieldset collapsing script. There seemed to be a conflict with Cufon and the collapsing script.

If you're happy with your invocation script, safe it in your theme folder as invoke-cufon.js

Step 4: Letting Drupal know about your scripts

We're going to open up your theme's .info file for this step. In your theme folder, there should be a .info file (Drupal 6 and up). The file contains a bunch of lines telling Drupal about the regions, meta data, and file that load with the theme. Add the following lines to the info file:

; Cufon Scripts scripts[] = cufon-yui.js scripts[] = Myndraine_400.font.js scripts[] = invoke-cufon.js

The script path is relative to the .info file and the filenames should reflect the names of the files you downloaded, so you need to change at least the name of your font file. It is important that you get the order right. If you don't lead the main Cufon file first you'll be spawning Javascript errors on your website!

Any time you add something to the .info file you need to clear the theme registry, you can do this by hitting the "clear cached data" button at the performance settings page.

If you did everything correctly you should now have awesome typography on your Drupal website, congratulations! If something went wrong just drop a comment below.

Can I use font X, Y or Z??

Unfortunately, font embedding and licensing form a complex issue. With most free fonts you'll be fine, with most commercial fonts you're going to have to pay extra for a webserver font license. From the Cufon website:

Fonts produced by the following foundries/vendors/creators are known to be safe: Adobe Systems. The following are known to require separate or extended licenses for Web Embedding: Berthold (separate), FontFont (separate), Fontsmith (separate), Hoefler & Frere-Jones (separate), ITC (separate), Linotype (extended).

So according to him you can embed Adobe fonts with a regular license. For most other Foundries you have to pay for a special license, and costs vary with foundries and with fonts. I've communicated with ITC a couple of times and they charged around 300 USD for their extended license.

Releasing a new basetheme!



Alldrupalthemes.com Basetheme v2 Display

Thanks:

  • Paul O’B from Sitepoint Forums for helping with researching for my holy grail of flexible Drupal CSS layouts.
  • John Albin from the Zen theme, for being a leader in Drupal theming innovation, and particularly for the awesome body/node/block/node classes code and the block edit/configure links.
  • Stephanie and Chris from TopNotchThemes for thinking up some awesome theme settings
  • Al Steffen from Studio theme, for pushing the limits at turning a Drupal theme into a nice organized collection of files.
  • Jacine Rodriguez from Sky theme, for laying the groundwork for Typographical theme settings, and more cool code.
  • All the rest of the Drupal community for working together on a free software project!

Features:

  • Color module integration (CSS only)
  • Live-preview mode for tuning colors. Any action by the color picker is immediately visible on the layout
  • Complete layout control! Supports flexible width, fixed width, percentage based columns and blocks, and it all works in internet explorer too!
  • Layout automatically adapts to no-sidebar one sidebar or 2 sidebar pages (retaining the set sidebar width and resizing the content column)
  • CSS file caching for enforcement of the theme settings.
  • Dynamic regions (horizontally) scale any number of blocks to fit next to each other
  • Full typography control with Cufon engine for selecting/adding custom fonts
  • Comes with 18 free fonts!
  • Animated dropdown menus with jQuery Superfish integration
  • Dropdown menu is configurable through the theme settings form
  • Various jQuery scripts to help make your website look sharp
  • Nodetype specific theme settings for node links and taxonomy links (adapted from acquia_marina)
  • Well organized and valid CSS 2 stylesheet, just approx. 1.000 lines.
  • Accessible and semantic HTML code. (and Search Engine friendly, of course)

Download it on the Drupal.org project page: http://drupal.org/project/adt_basetheme

Rationale:

This theme is the result of the work I've been doing, developing my drupal themes product line for alldrupalthemes.com, and it also includes many functions and classes that I have needed in the past 3 years, working as a freelance Drupal themer. I think the coolest part of the theme is the advancements I've made in recoloring themes, though this theme only uses the most basic parts of the color module, I've included some functions in the color/color-utility-functions.inc file that I currently use for my premium themes. It would be really cool if we could get a Color API in Drupal 7 to replace the color module, so that all the Color enthusiasts can collaborate to replace the old color.module.

The Cufon engine is also really cool, it's my first attempt to integrate Cufon with a Drupal theme. It was actually really easy, because you can just call upon Cufon with jQuery selectors. Cufon is a new competitor for sIFR, that uses VML and Canvas to replace browser text with embedded-font text.

The dynamic regions part is a simple solution to a complex problem, having a region that needs to have different CSS for every page that has a different number of blocks in this region. Basically it's just this:

// Widths of blocks in Dynamic regions
$precount = substr_count($vars['preblocks'], 'class="block ');
$postcount = substr_count($vars['postblocks'], 'class="block ');
$vars['postcount'] = $postcount;
$vars['precount'] = $precount;
if ($precount > 0) {
$prewidth = round(100/$precount,3);
}
if ($postcount > 0) {
$postwidth = round(100/$postcount,3);
}
$vars['blockwidths'] = <<

But then when you check it out in Internet Explorer you will find your blocks collapsing and stacking on top of eachother, but there is a very cool fix for this, a virtual buffer:

div.adtblocks {
margin-right:-100px!important; /* Create an invisible space (buffer) to allow overflow without collapsing */
padding-right:100px!important;
}

I will explain further in another blog post!

OMG WE'RE LIVE!!

Alldrupalthemes.com redesign teaser

Click the heading to see the rest of the Alldrupalthemes.com redesign, or go browse our new Drupal themes

Who now?

Today the new alldrupalthemes.com is officially going live. I have been talking about my awesome new themes for more than a year now but it's finally time to share. I hope that the direction I've taken with my themes will change the perspective people have of Drupal, as being the ugly ducking, and turn it into a awesomely extendable, flexible, configurable and re-colorable beautiful Swan!.

There is also a Design to Drupal service which is a service for superquick drupal theming gigs. This something I've been doing for years and I'm making this service faster and cheaper using the alldrupalthemes.com basetheme and Drupal/Storm based project management.

p.s. due the theming on alldrupalthemes.com is not 100% done, which is why the blog looks a little boring

Some coolness in the themes that I would like to highlight:

  1. Full color module integration. Including jQuery scripts that re-color the whole layout while you are dragging the Farbtastic Color Picker marker. (video coming soon).
  2. Filebased theme-settings CSS caching. I'll write a blog post about this later.
  3. Regions that can squeeze an unlimited amount of blocks in a space and divide the space equally, it's really simple but effective: if ($precount > 1) { $prewidth = round(100/$precount,3)-1; } where precount is the number of blocks in the "pre-blocks" region.
  4. Fully standards compliant code with accessibility features (skip to content etc.)
  5. Animated Dropd-down mennus with HoverIntent
  6. Both commercial and free support

Some background info: