Control Your Teasers

Drupal automatically splits off a leading part of an article to use as a front page teaser, and although you can control the nominal size of teasers by navigating to Administer -> Content management -> Post Settings, it doesn't really matter, because sooner or later you will run into a teaser that just doesn't work right.

Let me explain a bit about the teaser split that Drupal performs: when you post a content item, Drupal looks at the text, including all the hidden HTML tags, and tries to find a spot where it can break the content into two pieces, nominally at the character count setting established in Post Settings. That can be a little complicated, especially if the item has lots of complex HTML. In making the break, items with nothing but simple text will show more of their text in the teaser than items with lots of links in the opening lines, for example. Conversely, an <iframe> tag which drags in 256MB from a outside web source may end up appearing totally in the teaser, which really is the opposite effect you want.

There is a trick, however, to force Drupal to set your teaser right where you want it.

When editing a page, drop into Source mode, and insert "<!--break-->" where you want the teaser to end. Drupal will obey your manually entered break point, and not create its own.

Make sure you don't interrupt any tag open/close pairs when doing that, however. Annoying. Really. If your teaser breaks with a tag left open -- font color or size, or a <div> tag, for example -- your teaser may totally fry the appearance of the home page by causing the viewer's browser to interpret mismatched tags.

For most items, keeping the item formatting simple keeps you out of trouble. For the ones which don't format the way you want, consider putting the forced break in. For the really messed up ones, go into Source mode in the editor, copy the entire item, and paste it into NotePad++. Then you can set the language type to HTML, and let NotePad++ show you the HTML pairings.

Republican News


News & Views