Display Matrix block field base on location of query supportContent is a Matrix field
contentBlock is a Matrix block
heading and body are fields within contentBlock  

I am trying to display block.heading only if my query is in the block.body

{% for block in entry.supportContent.type('contentBlock') if query in block.body  %}
    &lt;h3&gt;{{ block.heading }}&lt;/h3&gt;
{% endfor %}


This code is not working. Any help?
Your code would work as-is if block.body was a Plain Text field.

But since it's a Rich Text field, it technically returns a RichTextData object and Twig's in operator doesn't know what to do with objects.

This will grab the string data from the Rich Text field so in operates as you'd expect.

{% for block in entry.supportContent.type('contentBlock') if query in block.body.getRawContent()  %}
    &lt;h3&gt;{{ block.heading }}&lt;/h3&gt;
{% endfor %}