6

I want to my teaser to trim to 400 characters, but the trim stops after the first <p> tag is closed. Is there a way to override this behavior and make the teaser trim to the first 400 characters?

I have edited the teasers 'manage display' option and set it 400, then edited and saved any old content, but the teaser is still being cut off after the first <p> tag ends.

I have considered adding a body summary but it does not allow any formatting in the box, which I require. Any help would be greatly appreciated.

  • Doesn't allow any formatting? – Capi Etheriel Jun 18 '12 at 11:57
7

I've been looking at this issue today and from what i understand the function used is text_summary which works in paragraph chunks - so if you have a short 1st paragraph and then a long second one, then it sets a break point after the first paragraph and stops there, so the 2nd paragraph isn't shown.

i'm currently using the smart trim module which allows trimming by words, and gets the desired result of a consistent block of text for a teaser view of nodes.

8

This solution works if you are using Views to display your content (if you aren't, it's up to you which is preferable in your case between using Views and getting its many other advantages, or installing Smart Trim and keeping things simple. Views is complicated but learning it is time well invested).

  1. Choose "Summary or trimmed" as the field's "Formatter"
  2. Set the "Trim length" value much too high - big enough that it will always cover the whole of all the elements you'll want trimmed (e.g. 1500)
  3. Under "Rewrite settings", select "Trim this field to a maximum length". Tick "Field can contain HTML", keep "Trim only on a word boundary" ticked, and enter the real character count in "Maximum length" (e.g. 200). It's a good idea to keep "Add an ellipsis" ticked to, so incomplete sentances don't look like a mistake.

So in our example, Drupal will choose the summary if there is one, or the body text if there isn't. It'll count 1500 characters, and trims cutting out any incomplete HTML elements. Unless your article contains an excessively long insane paragraph from hell, this will be at least 200 characters. Then Views' filter kicks in, trims it to 200 characters by the nearest word. This gives the real desired length, without losing the option of showing a trimmed version of the summary if there is one.

With "summary or trimmed" or "trimmed", the trimming is based on whole HTML elements so that long paragraphs can be cut out entirely. I've found that sometimes, if there's one long introductory paragraph, the trimmed field would show up completely empty - this solves that.

0

Under your content type -> manage display -> teaser -> under "Body" field, there is a "Format" drop down list. By default it is set as "Summary or Trimmed". Set this to "Trimmed" and then select the length to be trimmed.

If that doesn't solve the problem, maybe you can try the Teaser by type module.

  • FYI: The Teaser by type module is deprecated as the functionality is included in D7 core. – Chapabu Jun 18 '12 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.