How to hide body field in a view only on certain content types I have a search result view of different content types, and i want to show the body field (trimmed) on some content types, but show no body on other content types. Since they all share the same body field, I would need to exclude the body field from displaying on the content types that I don't want to see them on.

Right now I am doing this with Views rewrite results and CSS. I add the content type field and exclude, then add the body field. Under rewrite results I rewrite the output of the body field with this:

&lt;span class="search-body-[type]"&gt;[body]&lt;/span&gt; 

I then hide the content type bodies that I don't want to see with CSS:

span.search-body-MY-TYPE1,
span.search-body-MY-TYPE2 {
  display: none;
}


This works "visually", but the class and the trimmed body are still rendered in the HTML. Is there a better way to do this perhaps with a views_pre_render hook? 

(I am completely inexperienced with PHP.)
This can be done really easily with views_conditional module. Once you enable the module, having the content type and body fields already added and excluded from display, do the following steps:


add a views conditional field
set the if condition to the [type] == Indexed Content: Content Type
set is condition to contains
Set the value to the content type name for the body that you want to display
Then in Then output this... Use the [body] replacement pattern


Works like a charm!