<p>Your code would work as-is if <code>block.body</code> was a <a href="http://buildwithcraft.com/docs/plain-text-fields" rel="nofollow">Plain Text field</a>.</p>

<p>But since it's a <a href="http://buildwithcraft.com/docs/rich-text-fields" rel="nofollow">Rich Text field</a>, it technically returns a <a href="http://buildwithcraft.com/classreference/fieldtypes/RichTextData" rel="nofollow">RichTextData</a> object and Twig's <code>in</code> operator doesn't know what to do with objects.</p>

<p>This will grab the string data from the Rich Text field so <code>in</code> operates as you'd expect.</p>

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

CC BY-SA 3.0
2015-11-12T22:51:13.047Z
2015-11-12T22:51:13.047Z
Brad Bell
<p><code>supportContent</code> is a Matrix field<br>
<code>contentBlock</code> is a Matrix block<br>
<code>heading</code> and <code>body</code> are fields within <code>contentBlock</code>  </p>

<p>I am trying to display <code>block.heading</code> only if my <code>query</code> is in the <code>block.body</code></p>

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

<p>This code is not working. Any help?</p>

CC BY-SA 3.0
2015-11-12T18:59:02.817Z
What's `query`? A string?
Brad Bell
CC BY-SA 3.0
2015-11-12T19:20:23.293Z
Yes @BradBell `{% set query = craft.request.getParam('q') %}`
seth
CC BY-SA 3.0
2015-11-12T19:22:24.860Z
What's `block.body`? A text field?
Brad Bell
CC BY-SA 3.0
2015-11-12T19:26:40.847Z
`block.body` is rich text, `block.heading` is plain text.
seth
<matrix>
Display Matrix block field base on location of query
# Display Matrix block field base on location of query

(Asked by: username_0 on 2015-11-12)

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  %}
    {{ block.heading }}
{% endfor %}

This code is not working. Any help?

**Tags:** matrix

> **Comments:**
> **username_1**: What's `query`? A string?  
> **username_0**: Yes @BradBell `{% set query = craft.request.getParam('q') %}`  
> **username_1**: What's `block.body`? A text field?  
> **username_0**: `block.body` is rich text, `block.heading` is plain text.  

---

## 1 answers

### Answer by username_1 on 2015-11-12. Score: 1 | Accepted answer

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()  %}
    {{ block.heading }}
{% endfor %}


---

