Theming 101
Drupal 6 Template Variables - Going to the Source
Submitted by dale on February 3, 2009 - 11:01pmThe addition of preprocessor functions to Drupal 6 makes customizing template variables straightforward and clean (bravo to everyone who made this happen!). Have you ever wondered where the variables come from? It's actually helpful knowing, even if you're a themer with basic PHP knowledge.
Some reasons why:
- Seeing how the the variable is created allows you to make an informed decision on the best way of changing it. e.g., Modifying the theme function vs overriding the value.
- In the case of a module, knowing the logic behind how a variable is created can tell you whether or not a Drupal function should be used to add the information to the theming layer.
e.g. $head / drupal_get_html_head() / drupal_set_html_head() - Often a theme function is used to generate the variable. Copying the technique can simplify your code.
- Knowing the logic behind how a variable is created can aid troubleshooting.
In Drupal 6 the variable creation logic lives in the /includes/theme.inc file. The functions of note, located at the bottom of the file, are:
Theming 101 – The theme_links Function
Submitted by dale on June 7, 2007 - 12:20amThis article is an in-depth look at the theme_links function. Two notable uses of theme_links are theming a site's primary navigation links and, as of Drupal 5, the link list appearing in a node (nodelinks) i.e., Read More, Comments.
Changing these lists is a common theming requirement. After reading this article you'll be able to quickly determine if theme_links can handle your changes or if a new formatting function is required. You may also find the theme_links function appropriate for other uses in your theme or module.
Theming 101 – The theme_table function
Submitted by dale on May 16, 2007 - 2:24pmI 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.
