Transforming teaser/body fields output from a view

Events happening in the community are now at Drupal community events on www.drupal.org.
descender's picture

Hello everyone,

I'm looking to strip some HTML tags from the teaser/body fields output by a view. Specifically, I want to remove images, tables, etc., and retain only simple text markup (p, br, strong, em, etc.). Where and how can I add the code to perform this?

For CCK fields, I understand that this can be accomplished neatly with custom formatters. Does something similar exist for formatting node teasers/bodies?

Thanks in advance.

Comments

A few ways to do it

alexrayu's picture

There are a few ways to do it:
1. In the view field settings, set it to strip html. It will strip all html.
2. Use Views Customfield field set to PHP, put it after the field you want to process, see the name of required field with dsm($data) or print_r($data), and write php to parse that field or use some drupal prewritten code to do it. Set the actual field to "exclude from display" and display it's customfield processed variant only.
3. Use a views template to intercept and preprocess the field.

Thanks. Views Customfield is

descender's picture

Thanks. Views Customfield is exactly what I am looking for. I did fiddle around with Views templates but couldn't get the right preprocess hook to run.

I used this code for formatting the teaser field:

<?php
echo strip_tags($data->node_revisions_teaser, '<p><br><strong><em><b><u><i>');
?>

Can you please tell how to

Rameez's picture

Can you please tell how to use this code? thanks,

Cool, glad it worked

alexrayu's picture

Cool, glad it worked. I end up using customfield quite a lot for some tasks.

Theme development

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: