3

Teaser display has been set to display "summary or trimmed" at 200 characters but the auto generated trimmed body comes through with image tags, links and all.

I have tried the following in THEME_preprocess_node, but it results in a short trimmed version as it counts the html as characters -> trims to 200 -> removes tags:

if(isset($variables['content']['body'][0]['#markup']) && $variables['teaser']) {
    $variables['content']['body'][0]['#markup'] = strip_tags($variables['content']['body'][0]['#markup'], '<p> <br>');
}

This seems like surprising behavior, is trimmed not normally clean? PS this should ideally not be done in the template file.

7

You might want to take a look at the Smart Trim module. It gives all sorts of options for customizing trim functionality, including stripping HTML.

2
  • 1
    Nice module. Unfortunately the module description states: Note that HTML markup not seen by end-users will still be counted when calculating trim length. This may be addressed in future releases. This is exactly what OP wants to solve. – BetaRide Jul 20 '12 at 8:42
  • "Note that HTML markup not seen by end-users will still be counted when calculating trim length. This may be addressed in future releases." Even though the module page says this, the module does actually trim after stripping HTML. Some other cool options in there too, COOL! – Duncanmoo Jul 20 '12 at 9:14
0

You can implement hook_node_view or hook_node_view_alter and render the teaser the way you want it.

1
  • So make a module, apply hooks override teaser output, all seems a bit much for this. It feels like it should be in the display options for a text field. Thanks for the suggestion – Duncanmoo Jul 20 '12 at 8:24

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.