$layout (drupal 5.x) and $body_classes (drupal 6.x)

Last modified: April 3, 2008 - 14:56

PHPTemplate offers a variable in page.tpl.php which is rather powerful if you know how to use it.

Drupal 5 ($layout)

$layout contains a string telling you what the page layout is:
left if the left sidebar is in use
right if the right sidebar is in use
both if both sidebars are in use

Drupal 6 ($body_classes)

Even more powerful, the $body_classes variable contains some useful information, separated by spaces, that you can utilize in your css classes.

  • On the front page? front / not_front
  • Logged in or logged out? logged-in / not-logged-in
  • What node are we on? node-type-??
  • What are our sidebars doing? two-sidebars / one-sidebar sidebar-left / one-sidebar sidebar-right / no-sidebars

Some Drupal 5 themes already implement these classes, eg Zen.

Using it to your advantage

When you place these variables in classes, you can more easily make your theme more versatile by being able to handle the diverse block settings users will choose. The strings these variables contain are purposely designed to be used in CSS classes.

 
 

Drupal is a registered trademark of Dries Buytaert.