Smart Trim allows you to control the length of your content by trimming it intelligently. It is designed to be a focused, lightweight improvement over Drupal core’s current formatter trimming capabilities. The maintainers’ focus is stability and ease-of-use. Customizations to the module are encouraged with template overrides and Smart Trim hook implementations.
After installing and enabling Smart Trim, you will see a “Smart trimmed” option in the format dropdown for your text fields. For content types, this is located on the “Manage Display” page.
Once the “Smart trimmed” formatter is selected, the following configurations can be controlled:
- The trim length
- Whether the trim length is measured in characters or words
- Appending an optional suffix at the trim point
The Summary option is to determine how the formatter will act if there is summary data present in the field. You can either use the summary as is, trim the summary based on the settings provided, or skip the summary all together and just use the trim settings against the field value.
There are additional settings available which help troubleshoot
- Stripping out HTML tags from the field
- Still apply output if there is a zero length trim
- Replace any tokens before trimming.
There is an option to wrap the trimmed content in its own container, however this is deprecated. A template file is provided which can be overridden. This template file can also be used in place of the “More Link” settings, seen below. However if one does not want to use the template file there are options one can set in the administration UI.
In conclusion, the Smart Trim module is a useful tool for controlling the length of your content in Drupal. For more information, there is full documentation and as always, any questions or issues can be addressed in its issue queue.
Mark Casias has been developing and maintaining Drupal sites for many years, and is an active part of the community, adding core commits and a few of his own modules. works at Kanopi Studios as a Drupal Tech Lead. Outside of his home office in Albuquerque New Mexico, Mark plays bass in The Randomatics and enjoys ice hockey.