Planet Drupal

Theming 101 – The theme_table function

I come to you as one reformed. I will no longer use foreach loops to build tables. At first, I did not know about theme_table. Then I couldn't be bothered to learn about it. Then, after feedback from people whose opinion I respect, I felt compelled to bite the bullet. I wish I hadn't waited so long.

Overview

As the name suggests, theme_table is a Drupal theming function for creating tables. It takes arrays holding the table data and generates the HTML for displaying the table. At their simplest, the input arrays hold text elements. At their most complex, the arrays hold arrays which hold arrays. The various arrays all hold data appropriate to their location, so this isn't as bad as it sounds.

As with all Drupal functions, there's documentation at api.drupal.org. For the Drupal 5 theme_table function specifically: api.drupal.org/api/5/function/theme_table. There's enough there to get you started, but you still have to think a bit. (Which is to say, I had to. Think a bit, that is.) Thinking should be reserved for the problem at hand, not figuring out Drupal, so here's my "overflowing with examples so you can cut and paste" explanation of theme_table.

April 2007 Vancouver League of Drupaliers Meeting

April 26, 2007 saw a close encounter of the Drupal kind at the Bryght offices in Vancouver's Gastown. Attendance wasn't counted but people were scrambling for chairs. Meeting topics included:

  • OSCMS Roundup
  • Drupal 6 Update
  • Scott Hadfield's Summer of Code Project on Drupal Scalability
  • Install Profiles
  • Pro Drupal Development Book
  • General Q&A

What follows are my notes from the meeting, including audio excerpts (Recording credits go to Roland Tanglao and myself).

April 2007 Drupal Meeting

Video Sharing Implementation Discussion

An interesting post at Open Academic on doing video in a variety of CMSs, including Drupal:

DIY: Private Video Sharing for a school, a district, or an organization

Theme Variable Total Visibility

Need to know absolutely, positively, and without-a-doubt what theming variables are available to your template? Here's a trick for total visibility.

In my previous post, Take Control of Your PHPTemplate Variables, I described the _phptemplate_variables function in template.php. It's passed a parameter named $vars which is an associative array of all the variables that will be created in the template . . . which is exactly what we're looking for!

Since _phptemplate_variables allows us to create theme variables, we have a simple way to get the $vars data into the template where we can look at it. Just put the following code in your template.php file:

function _phptemplate_variables($hook, $vars) {
  return array('vars_data' => $vars);
}

And the following code in your template file:

Take Control of Your PHPTemplate Variables

For your templating pleasure Drupal's PHPTemplate engine makes available a cast of variables, including such favourites as $title, $content, and $node. Modules also contribute: CCK adds CCK specific template variables as well as fields to the node object, and the comments module adds an entry to the $links variable. But what happens when something isn't formatted the way you or your customer wants, or you have a project specific variable you want to add?

Introducing the _phptemplate_variables function!

The _phptemplate_variables function lives in your theme's template.php file and is called by the PHPTemplate engine after the various modules have done their thing, and before PHPTemplate actually renders your node into HTML. _phptemplate_variables provides a single, common location to all .tpl.php files for adding or changing variables.

ONLamp.com Drupal/CiviCRM mention

Drupal/CiviCRM gets a prominent mention in this ONLamp.com blog post: Top Drupal & CiviCRM Gotchas

Seven of his ten points are good to know for any LAMP based system, and some are aimed squarely at the new (e.g., do backups). Great information for someone starting out, but given the general nature of the information the post is a little misnamed.

Simon Willison's Slidecast on OpenID

OpenID LogoI've been hearing a lot about OpenID the last six months, probably because Sxip and Bryght have a local presence. It's a cool technology solving a problem I certainly deal with day-to-day. But will it rise from the primordial idea soup into mainstream acceptance? According to Simon Willison, yes:

When Bill Gates stands up at a security conference in America and spends seven minutes on stage talking about a technology, it's not really a niche proposition anymore.

Evil Ben and MenaWilson recently gave a talk that was converted into a "slidecast": http://simonwillison.net/2007/Mar/12/slidecast/. It does an excellent job, the best I've seen to date, of explaining OpenID and the problems it's meant to solve. I appreciated his inclusion of a "What's wrong with it?" section. And it's not without humour, we're introduced to the evil alter egos of Ben and Mena Trott!

More Lullabot Article Goodness: Forums & CCK

Lullabot

A shout-out to the folks at Lullabot for their latest articles:

Notes from Mack Hardy's Drupal Talk

This month the Vancouver PHP Association and Vancouver League of Drupallers had a combined meeting. Mack Hardy of the Post Carbon Institution spoke on how the Post Carbon Institute was using Drupal to meet their organization's goals.

Mack has promised to post his slides, and hopefully there will also be a video of this presentation available. My summary forgoes the more involved details. Please check the slides for those.

Mack started with an overview of the Post Carbon Institute:

Post Carbon Graphic

Drupal Dojo Lesson Links

The Drupal Dojo lessons are now listed in a nice table of contents style format: Dojo Lessons and Links at the groups.drupal.org (aka D.O.) site: groups.drupal.org/drupal-dojo.

Pages

Subscribe to RSS - Planet Drupal