Drupal 6 Teasers: Buggy as Ever

Drupal 6 has introduced quite a few changes that make previously tedious programming tasks a breeze, through better code modularization and a slightly more granular API.

Except for when it comes to teasers.

In previous versions of Drupal, teasers could be modified with a simple change to the teaser string inside of the node object following a node-submit operation.

Unfortunately, modifying the teaser in the same way in Drupal 6 is not so clear-cut, because of certain "enhancements" made to the teaser system that, in my opinion, make too many assumptions for their own good.

The enhancements I'm referring to are Drupal 6's ability to allow users to "split" their body text, specifying where the teaser ends and the rest of the body begins. Drupal does this with a breakpoint marker in the form of a regular HTML comment. So far, so good.

The problem comes into play when Drupal loads a normal node edit form. Without being clear at all about what it's doing, Drupal:

1. Loads some teaser-enhancing Javascript code
2. Prepends the teaser text (with the "break" comment) to the body if it can't find the teaser at the start of the body already.

#1 makes the assumption that you want to be able to dynamically split the body text into a teaser, which is nice for a blog, but not necessarily desired for a CMS.

The second behavior doesn't work for anyone wanting to modify the teaser because it assumes that the teaser is going to be an opening subset of the body. If the teaser has been modified to no longer match an opening portion of the body (exactly), then the system will repeat the teaser at the beginning of the body, resulting in a seemingly duplicate portion of text at the beginning.

The solution for me was to trick Drupal into thinking, on the node edit page only, that the node teaser is equal to the node body.

In general this was pretty annoying, considering that Drupal 6 teasers are still barely configurable, prone to buggy behavior (not handling opening P tags correctly, not closing HTML tags), etc.

But, in the end, it's Drupal, and enough control is available to turn off the special teaser handling features through hook_nodeapi and hook_form_alter.

Back to top