Drupal user account pages

Written at 07:10, on Thursday 9 October 2008. Tags: drupal .

It’s the little things that count…

On a default Drupal installation, the user account could really use some love and attention. There are a number of predefined pages to allow users to register themselves on the website, but the usability of these pages is pretty bad. This post is about one little example: they all share the same title. I’m going to show you how you can fix that.

Have a look at the drupal.org register, log in and request new password pages. You’ll note that each one has a head title of “User account | drupal.org”, and a page title of “User account”. While each page certainly has a different function, why would they all have the same titles? That’s just weird and plain bad usability – a page title should be descriptive of the main function of a page.

Anyway, there are ways to override that. Drupal uses a placeholder variable to dynamically determine the page and head title based on the internal path. In your theme, you’ll find something like the following:

<title><?php print $head_title ?></title>

And:

<h1><?php print $title ?></h1>

Since Drupal determines its context based on the path that is requested, simply checking for the arguments which are passed to the page is enough.


<h1><?php 
if (arg(0)  'user' && arg(1)  'register') :
  print t('Create new account');
elseif (arg(0)  'user' && arg(1)  'password') :
  print t('Request new password');
elseif (arg(0)  'user' && arg(1)  'login') :
  print t('Log in');
elseif (arg(0)  'user' && arg(1)  '') :
  print t('Log in');
else:
  print $title;
endif; 
?></h1>

It’s really simple PHP, checking for the first and second arguments (arg(0) and arg(1)). Note that instead of printing out the text, it’s wrapped in the t function, which will make it translatable. That way, you don’t have to edit the theme in order to translate your texts afterwards.
As you can see, there are two checks for the login page. That’s because both the user and the user/login pages present a login page, and the Drupal menu that is presented on the account pages defaults to the user page. So we have to check if the second argument is empty, and if it’s not, print the title of the login page. If we didn’t add that extra check, we’d have overridden the default user account pages, which all follow the form user/uid, where uid is the numerical id of the user.

Just adding the same checks to the <head> title will suffice to change it there as well. Full credit goes to the Drupal community, as this snippet is based on drupal.org. You can see it in action on the new CJP website: login, register and forgot password.

Comments closed |

From the portfolio

  • Musicminutes Cycle Systems Group landingspage

About this website

My name is Jeroen Coumans, I'm a freelance web designer, front-end developer and Drupal ninja from the Netherlands. I love to create beautiful, usable and accessible websites. On this website, you can find my portfolio as well as my personal weblog. Interested in hiring me? I'd love to hear from you.

After completing my BA in Arts and Culture I'm now doing a MA in Communication and Multimedia Design. More …

Elsewhere

Issuu and Smart Look for a better PDF viewing experience

A plugin that embeds PDF's, Word and Powerpoint files in a very cool, usable and fast Flash interface.

Visit site …

Palm Pre: everything you ever wanted to know - Engadget

This is the only device I would consider as replacement for my iPhone. Palm seems to have done some essential things right, like contact management by pulling data from various services in the cloud. I love the zoomable UI and the card metaphor for app switching.

Visit site …

Release:jQuery 1.3 - jQuery JavaScript Library

Some very nice features and performance improvements in this release, among which the Sizzle CSS selector engine (currently fastest avaiable), live events and much faster HTML injection.

Visit site …

jQuery API Browser v1.3

Improved and also available offline as AIR app.

Visit site …

A List Apart: Articles: Return of the Mobile Style Sheet

"What can be done for mobile browsers that do not read handheld style sheets, or parse CSS Media Queries? Short of ignoring them, there are two options."

Visit site …

Mapeed.AddressChooser API documentation | Home

Cool Javascript component that can be used for address collection in forms, combining HTML form and Google Maps for dynamic place retrieval and auto-completion.

Visit site …

Digital Ethnography

Blog of Michael Wesh, cultural anthropologist, professor of the year, and creator of the video "Web 2.0 … The Machine is Us/ing Us".

Visit site …

Components Versus Patterns

Analysis on the differences and commonalities between components and patterns. "Although the two concepts are strongly related, their differences warrant consideration to ensure you are building the type of library that’s right for you."

Visit site …

The State of the Web 2008 | Web Directions

"Welcome to this detailed report from our first “State of the Web” survey of professional web designers and developers. It includes details and analysis of all the responses to over 50 questions covering technologies, techniques, philosophies and practices that today’s web professionals employ."

Visit site …

The Curious Case of Twply and Twitter - Bokardo

Excellent interface analysis of twply: "Moral of the story? Design can effectively be used to deceive people. Deal only with those services you know and trust. "

Visit site …

Subscribe

Or choose one of the single feeds:
Journal feed | Elsewhere feed