Add something new to Virb:

Virb

Are you sure you want to delete that?

or Cancel

 

Posted on Oct 9, 2008

Drupal user account pages

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:





And:





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.







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 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.

Loading comments...

Likes

Details

Viewed 36 times

© 2008 Jeroen Coumans

virb.com/t/863675
tweet!

Flag this text post!

Flag this text post as:

or Cancel

 

Advertisement

Flag this profile!

Flag this profile as:

or Cancel