Want to get Lullabot article, videocast, and podcast announcements delivered right to your in-box? Let us know your email address (we won't share it) and we'll let you know when anything exciting happens.

Customizable Header Images for Your Drupal Theme

The dark days of Drupal theming are history. Today, it's pretty easy to find a slick design for your site, and if you need to build one from scratch there are great training tools to make the process painless. (Shameless plug: Lullabot's Theming Basics and Advanced Theming DVDs are a great resource!)

What's still relatively uncommon, though, is support for user-friendly customization by non-designers. Drupal 5 shipped with the re-colorable Garland theme, and a handful of themes support the same feature via Color module. The Nitobe theme offers a choice of header images; Development Seed's Singular theme lets administrators upload a custom background image for a site; and TopNotchThemes' Fusion theme allows administrators to choose fonts and switch from fixed-width to liquid layout using a settings screen.

Adding these kinds of customization options to a theme can make a huge difference in usability for end users and administrators. In this article, we'll learn how to add a "header image" setting to a theme, allowing a site manager to change the site's header from the administration screen!

read more »

Single Sign-on across Sub-Domains in Drupal with No Extra Modules

With the multitude of single sign-on modules out there for Drupal, it's easy to miss the fact that Drupal has a built-in single sign on mechanism already. No modules, no configuration, just 20 easy lines of PHP in your site's settings.php file. This solution works for a lot of clients, but the set of requirements is pretty specific as to when you can use this approach. This includes:

  • The sites sharing a single log-in must be on the same domain. For example:
    • www.example.com
    • forums.example.com
    • subsite.example.com
  • You must be using MySQL.
  • Your sites must be on the same hardware cluster to be able to query each other's databases.

If your site fits within those requirements, you're on your way to simple, efficient, and easy Single Sign-on!

The concept for this single sign-on approach is based around Drupal's ability to prefix database tables. As you may know, you can run multiple Drupal sites on the same MySQL database. However, most sites are not configured this way, each site is given it's own dedicated database. Drupal's table prefixing can be combined with MySQL's ability to query across databases to make a simple "shared table" across multiple sites. Then you just need to set a cookie domain so that the two sites share session information and you're done!

read more »

Analyze This! Using the Google Analytics API

Google Analytics is a great way to monitor site usage and traffic. You add Google Analytics to your site using the Google Analytics module, which is super simple to set up. After it's in place, you can go to the Google Analytics site and dig into a ton of data, create custom reports, etc.

But you can also use the Google Analytics API to pull Google statistics into your own site and display them there. There is a Drupal module, Google Analytics API that was created by Joel Kitching as a Google Summer of Code project. It provides a wrapper you can use to create tailored queries of your analytic data. You can turn on the included 'Google Analytics API Reports' module to display Google statistics in blocks or pages right on your site, and/or create custom code to suck in specific statistical data and do any Drupally thing you like with the results.

read more »

User Management for Real World Groups

Drupal's default methods of handling user names, emails, and registration processing work pretty well out of the box for many web sites. Drupal assumes your users are online, have unique email addresses, and that you want to create a site that grows organically as users find it and register themselves. Drupal out of the box may not work so well for real-world groups of people where the group already exists and consists of specific people who may or may not be online, may or may not have unique email addresses, and may or may not be able or willing to register themselves on your site.

Some good examples of the problems I have run into are creating web sites for families, clubs, and churches, but the same problems exist for any other real world organization or group. They have established groups of members, some of whom may share email addresses or have no known email address. And in these cases the administrator will probably create user accounts for everyone rather than waiting for users to self-register. On top of that, we may want some control over usernames so that users can recognize each other once they do get online, by forcing the username to be FIRSTNAME LASTNAME.

This creates several problems that have to be overcome creatively. After several years of trying various approaches, here is a summary of the problems I ran into and the ways I eventually solved them. I have included links to the ones I discuss, with the number of downloads in the week of November 22 as a measure of how commonly used they are.

read more »

Drupal data imports with Migrate and Table Wizard

If you haven't yet heard the buzz that's been building since Drupalcon DC in March about the fabulous Migrate and Table Wizard modules, written by the smarties at Cyrve, then here are a few questions for you:

  • Does the phrase "data migration" conjure up images of being repeatedly stabbed in the knee with a rusty fork? (which would of course be a far more enjoyable experience!)
  • Have you spent countless hours sifting through record after record of your clients' legacy data, pining for an easy way to catalog it all so you (and they!) can both tell what's really important to pull over?
  • Do you lose years off of your life every time you attempt a bulk migration, hoping for the best that there are no horrific bugs that need to be sorted out afterwards that you didn't catch in testing?
  • Have you had it up to here with having to go and find separate modules, each with totally different interfaces and levels of bugginess, for importing nodes, taxonomy, users, and so on?

If you answered yes to any of these questions, then the Migrate and Table Wizard modules are for you! Read on to learn how they work and try a "hands on" example.

(Note: This article is written against the current -dev releases of both Table Wizard and Migrate, which will eventually become Migrate 6.x-1.0 and Table Wizard 6.x-1.2. Final screen shots may vary.)

read more »

Drupal Performance Tip: Block Visibility

This is something we hit a lot when doing performance analysis on very slow websites, so I figured I'd issue a public service announcement. :)

It's not uncommon in more complex themes to have many different block regions, and even dynamic regions that will only appear on certain pages or when viewing nodes of certain types. One very common use-case is to have both a page.tpl.php, and a page-front.tpl.php, each of which print out different regions, particularly for ads or promotions:

Block region examples

Defining block regions is super easy; simply add a couple lines in your theme's .info file:

regions[ad_top]        = Ad Top
regions[ad_bottom]     = Ad Bottom
regions[front_sidebar] = Front Sidebar
regions[sidebar_ad]    = Sidebar Ad
regions[content]       = Content
regions[feature_a]     = Feature A
regions[feature_b]     = Feature B
regions[feature_c]     = Feature C
regions[feature_d]     = Feature D

And then in your *.tpl.php file, wherever you want the region to appear, simply print out its machine-readable name:

<?php
print $feature_a;
?>

Don't want the blocks in the "Feature A" region to show up in page.tpl.php? No problem! Just don't print the region out there! Done! Right?

read more »

Bringing Drupal to the U.S. Government

Government Seal DropWe had a great week of on-site training at the Department of Commerce in Washington, DC last week. They've already launched recovery.commerce.gov in Drupal and they're currently in the process of rebuilding Commerce.gov as a Drupal site. We spent the week with their team making sure that they understood not only how to build and present a Drupal site, but also the benefits of the Drupal community. They're a smart bunch and it's always fun to watch the synapses sparking as people realize all of the ways that they can snap together Drupal's pieces to create interesting web functionality.

There seems to be quite a buzz around Drupal in the government and as the Commerce team walked around the building with Drupal books under their arms, they got lots of comments from people in other bureaus, saying, "Oh! Drupal! We're thinking about using Drupal." Word is starting to get around about Drupal as a great platform for government websites.

There was a lot of excitement in the Drupal community when Recovery.gov originally launched using Drupal. And while the site has since upped its budget, redesigned, and moved off of Drupal, I still think that this is a win for our humble CMS. The site was built quickly on Drupal and launched within one month of Obama taking office. Shortly after launch, the site was getting 3,000 hits per second! That's a huge amount of traffic for any website, not to mention one built so quickly.

read more »

Installing Memcached on RedHat or CentOS

Memcached is a service that allows entire database tables to be stored in memory, drastically speeding up queries to those tables and alleviating database load. In Drupal, the Memcached module allows you to store all cache tables in memory.

We've covered how to install Memcached before on Debian and on Mac OS X. But server software can vary significantly between sites, and this guide can be used to set up Memcached on Red Hat Enterprise Linux (RHEL) or CentOS, which are architecturally the same.

Install memcached through RPM

The easiest way to install Memcached is through a package manager such as yum or apt. However, Memcached is not available from the default collection of packages, so the first thing we need to do is add a new RPM (Red Hat Package Manager) server so that we can install Memcached through yum.

One of the best 3rd-party RPM servers is provided by Dag Wieers, which will provide us with up-to-date packages that are not provided by Red Hat directly. The one tricky part of setting up an RPM server is making sure you get the repository that matches your server version and architecture (32-bit or 64-bit). So we need to collect that information first.

From a shell prompt, get the CentOS/RedHat version number:

read more »

Learning JavaScript from PHP - a Comparison

This is a basic comparison between PHP and JavaScript. It's intended for users familiar with PHP and looking for JavaScript equivalents.

JavaScript and PHP Comparisons:

Variables

Variable Scope

PHP and JavaScript take two very different approaches to declaring variables. In PHP, all variables are local in scope unless declared as global. JavaScript is opposite, and all variables are global unless declared with the var keyword.

read more »

My Aha! moments in Drupal theming

While at Drupalcamp Copenhagen I got into a few conversations about Drupal aha! moments, particularly around theming. After trying to talk in the abstract about the things that finally "clicked" for me when I was learning Drupal, I offered to write it up with some specifics. So, for my Danish buddies and any other curious Drupalers, these are my two biggest aha! moments that accelerated my Drupal theming ninja skills: "getting" the theme system and working with forms. I've already written about modifying forms and since "getting the theme system" is a big chunk, I'm going to focus just on that moment in this article.

read more »
Syndicate content