Drupal.behaviors: The Two Step Secret To Unlocking Drupal's Javascript

The hardest part about using drupal's javascript features is knowing where to begin: they remained an arcane mystery to me until today. After drinking a bit of whiskey, and studying how core was using Drupal.behavior, I learned it couldn't be simpler. If you don't know how to do this, take a moment:

Overriding Menu Page Callbacks

Sometimes you need to override more than a theme function: the entire page needs to be overridden. Drupal 6 makes it rather easy to do this.

In the example below, we call hook_menu_alter(&$callback) to override the display of every single node page view.

Instead of returning a node page, we return "[author's username] is great... for me to poop on.".

 

hook_theme and tpl.php files: registering them with drupal, and passing variables

There is one way to let drupal know about a theme function or template. There are two ways to send variables to a template, but one of them has a lot of disadvantages.

We'll use two theme functions, with an identical template setup to illustrate these methods:

Creating Theme Functions and Routing Them to a Template

There's only one way, hook_theme()

Loading a Menu, and Theming the Links in Two Lines of Code

When creating a menu [ admin/build/menu/add ] there's a field for "Menu name". We use that value to load whatever array of menu links we want. In this example, we're using "secondary-links" which comes default on most drupal installs.

Five Drupal 6 WYSIWYG Editors Reviewed

Tags:

I reviewed 5 WYSIWYG editor modules for drupal 6: FCKEditor, TinyMCE, WYMeditor, jwysiwyg, HTMLBox. The latter three aren't yet mature, so I saved the in depth reviews for the big guys, tinyMCE and FCKeditor. Truth be told, I decided to have low expectations, and rated these modules against the following:

Never name a theme and a module the same thing

Lets say you're building a drupal website for Bill's Widget Company. You create a custom theme, and a custom module. Now lets also say you are as dumb as me, and decided to name both your theme and module the same thing: bwc. Its a small mistake you'd never make if you thought for a second: "Should my module and theme share the same drupal namespace?" It sounds dangerous, even if you don't know why. Here's why it is dangerous:

Good Times

Now that my employment situation has settled*, I'm feeling great. I forgot how much I loved doing client projects. Compared to a startup, where the problems are extremely complex, the possible solutions are many -- most of them wrong, and the pace is back breaking, client work is relatively straight forward: figure out what they want to do, and put together some technology that does it.

Moving On

Left my two year position as web developer/designer at a start up today. Contact me if you're looking to hire a drupal ninja.

The Worse Things Get, the More the OP/ED Section Shines

I can't remember the last time I read so many noteworthy quotes:
Bob Herbert:

Pages

Subscribe to Nick Lewis: The Blog RSS