Posted by descender on April 14, 2011 at 1:44pm
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
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
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:
<?phpecho strip_tags($data->node_revisions_teaser, '<p><br><strong><em><b><u><i>');
?>
Can you please tell how to
Can you please tell how to use this code? thanks,
Cool, glad it worked
Cool, glad it worked. I end up using customfield quite a lot for some tasks.