theming
Drupal 6 RSS Omnibus
Submitted by dale on July 27, 2009 - 12:11pmDrupal RSS functionality is spread out, and so is information on it. After first accumulating mental notes, which turned into a collection of written notes and code snippets, I realized there's a lot to be said on the topic. A single overview covering all things RSS seemed like a useful idea. This is a starting point covering many things RSS. I invite you to leave a comment if you have anything to add, a great reference or blog post, or if I've gotten something wrong.
"Out of the box" RSS
- RSS is configured and controlled at Administration > Content management > RSS Publishing

- The default RSS URL is rss.xml (e.g. www.example.com/rss.xml)
- The default RSS feed selects content using the same selection criteria as the /node path ("/node" is the default front page setting). It contains the content of any node that's both "Published" and "Promoted to front page".

The exact content and number of nodes is determined by the RSS settings. - There is no provision to theme a node's RSS output in the PHPTemplate theme engine. Your node.tpl.php file is ignored when the feed content is rendered.
- Because of the above point, double check the RSS feed output of any feed containing nodes you've created or modified with CCK.
- Every taxonomy term automatically gets a feed (whether you want it or not)
- The is no provision in the Drupal base installation (core) to publish comments in a RSS feed. A contributed module (RSS Comments or Views) is required. More on this later on.
- The RSS feed will only be published on the front page. More on this later.
"Taking Logic Out of Your Template Files" from Drupal Camp Victoria 2008
Submitted by dale on February 18, 2009 - 4:11pmRene Hache of North Studio presents Taking Logic Out of Your Template Files at Drupal Camp Victoria 2008. In this session Rene discusses template file theming and the separation of presentation and logic. It proved an engaging session with the Q & A lasting almost as long as the original session. By popular demand, Rene made the North Studio base theme available for download from the Drupal Camp Victoria website: northstudio.com Theme.
DCVic08: Taking Logic Out of Your Template Files
The video can also be viewed directly: DCVic08: Taking Logic Out of Your Node Template Files at blip.tv
For a summary of Drupal Camp Victoria check out: Drupal Camp Victoria 2008.
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 Views 2 – The Basics
Submitted by dale on December 29, 2008 - 6:46pmViews 2 provides a well structured theming environment allowing presentation control for each element of your view. And in my humble opinion, it rocks!
Those with no past experience with Views 1 will find Views 2 uses standard PHPTemplate theming techniques. All of your experience theming Drupal can be used with Views.
Views 1 themers starting with Views 2 might be a bit confused at first. I was. The single callback in template.php where everything happened is gone, refactored into a consistent framework of template files. All of the freedom that existed in the single function still exists with the added benefit of a well defined structure.
Overview
Views handles querying the database and organizing the information for display. It creates the output display by converting retrieved data into variables and passing them through a series of templates. Each template handles a different "level" of output creation. The number of templates used to create a view's output depends on the view's type and style, as well as the number of fields involved. These templates exist as files (with a .tpl.php extension), in either the module's or the theme's directory, and follow PHPTemplate's theming conventions.
Generally speaking, the template levels are:
A New Look
Submitted by dale on October 12, 2007 - 2:30pmThe project didn't start as a new look.....
I've been mulling over some updates to the site and when some open time appeared I decided to make them, but I kept coming back to wanting a theme change. I couldn't shake it! Voodoo Dolly's narrow fixed width was grating on me, and I didn't want to invest the energy needed to change it. A number of nice themes have been added to the Drupal theme listing, so I picked Danger4k. And now:
Welcome to the new look!
I can now return myself to my originally scheduled updates.
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.
Theme Variable Total Visibility
Submitted by dale on April 25, 2007 - 11:28pmNeed 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
Submitted by dale on April 23, 2007 - 7:21amFor 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.
Template Theme Variables
Submitted by dale on February 4, 2007 - 10:34pm[Update 2007-Apr-29: Please also see the article Theme Variable Total Visibility]
Have you ever wanted to know what variables the phptemplate engine made to the node or page templates? "Use the source, Luke" (Couldn't resist). The way of finding the definitive answer was discussed in Drupal Dojo today.
