This module extends text field formatter settings (as seen on "manage display") to allow you to choose a different "text format" or text filter at the same time as the normal choices of "full" or "summary".

Use case

Use it to

  • Create super-simple teasers by removing block elements and headings. This will prevent unwanted markup from leaking onto your front page or lists, even if your content editor does try to insert an inline image into their first paragraph.
  • Use special enhancement filters like toc, tabs, glossary or chunker only in very specific view modes or for specific content types - in a way that does not require the content editor to manage the text formats.

Also provides: The Anti-teaser : 'Remainder after trimming'

D7 only, D8 TODO

What if your layout requires the body text that is *not* the teaser? This can be somewhat managed on the editorial level already, but if you want to make use of the automatic teaser *and* you want a layout where your intro text is separated from the rest (eg by inserting the author/dateline under the intro) then you need some way to say "the *rest* of the body text.

This is a new rendering option under field display settings for longtext fields. See the README for setup suggestions.

Requires:

D7

D8

  • Core only (Field UI enabled)

Usage

Additional settings can be found when editing an entity types field settings,
eg at /admin/structure/types/manage/page/display
If you choose "default", "trimmed", or "summary or trimmed", on a longtext field, there will be additional options in the settings for that field.

The normal per-node text format filter will always be run first so security filters are still in place. This display tweak runs an additional process as part of the rendering.

Quickstart

  • Given a 'page' content type, with a WYSIWYG editor in place for managing full-body content, and a loose "Full HTML" or "WYSIWYG markup" filter in use.
  • Make a page that includes lots of scary markup in the first few paragraphs; embedded images, h2, lists, alignments, blockquotes.
  • Visit a place that displays a 'teaser' of your page (eg promote the page then visit /node). Observe that it looks pretty inconsistent with whatever you expect teasers to behave like.

To resolve this

  • Enable this module and its requirements. Ensure core "Field UI" is enabled.
  • Visit /admin/config/content/formats/ and add a text format called "Safe teaser markup" or whatever label makes sense to you.
  • On that format, Use "Limit allowed HTML tags" and reduce the allowed set to remove anything that will throw off the layout. Leave only minimal rich-text (inline level elements, and maybe 'p') behind. <a> <em> <strong> <p> <br> is enough to start with.
  • Visit Administration : Structure : Content types, and "Manage display : Teaser", eg for your "Page".
  • The Body: Format should probably be "Summary or trimmed" (the default), but now open up the Format settings.
  • Now you can apply an "Additional text filter", so choose "Safe teaser markup".
  • Save the format setting, and save the teaser display.
  • Visit your teaser page again and see that sanity has returned to your teaser layouts.
  • ... revise your filter rule to be as permissive or strict as your theme requires.

Caveats

Running two text filters one after the other can have unexpected side effects, so it's recommended that the per-filter format be pretty simple, and restrictive (not additive).

Running an aggressive strip_tags process after the text has already been trimmed once to teaser-length can reduce the character count even more than expected.

Drupal 8 Version

The first release of the Drupal8 version differs slightly from the D7 one:

  • The field-manager-defined text filter is used instead of the one configured for the content text field, instead of running as well as the usual filters. This may have implications. The 'both' filters behaviour will be re-instated when we figure it out.
  • The anti-teaser formatter is not supported yet. May be added again later

See also

Previously, for many years we would just hack the theme template node.tpl.php (D5,D6) or with theme preprocessing (D7) and run strip_tags on the $body for teaser mode. Always felt like a hack.

With D7 field formatters, you can now choose 'plain text' but not 'trim' at the same time, and vice versa.

Smart Trim offers more precise control over teaser configs in a new display formatter, though it doesn't re-use text format filters.

advanced_text_formatter looks like a worthy (D8 possible) successor

Differences from advanced_text_formatter:
advanced_text formatter injects all the stuff you want directly into each per-field settings. That works great once, or on small sites, but has the potential to get inconsistent over multiple content types and view modes. You have to ensure that all the tags you allow or block are kept in sync.

The approach used in this module is to re-use existing core-managed 'text formats' as a single, re-usable formatting choice.

Both are fine for different reasons. advanced_text_formatter provides more fine-tuned per-display choices, field_formatter_settings provides more consistent, re-usable preferences.

In the interests of consolidation - you should compare and contrast this utility with advanced_text_formatter and make your own choice.

Credits

Sparks Interactive LogoThis module was built with the support of Sparks Interactive - a New Zealand company supporting the Drupal Community!

Supporting organizations: 
MODULE-A-WEEK initiative 2016!!

Project information

Downloads