Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-12T22:51:13.047Z
Answers.LastActivityDate: 2015-11-12T22:51:13.047Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-12T18:59:02.817Z
Comments.Text: What's `query`? A string?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-12T19:20:23.293Z
Comments.Text: Yes @BradBell `{% set query = craft.request.getParam('q') %}`
Comments.UserDisplayName: seth
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-12T19:22:24.860Z
Comments.Text: What's `block.body`? A text field?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-12T19:26:40.847Z
Comments.Text: `block.body` is rich text, `block.heading` is plain text.
Comments.UserDisplayName: seth
Tags: <matrix>
Title: Display Matrix block field base on location of query
ThreadText: # 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  %}
      <h3>{{ block.heading }}</h3>
  {% endfor %}
  
  ```
  
  This code is not working. Any help?
  
  **Tags:** matrix
  
  > **Comments:**
  > **username_1**: What's `query`? A string?  
  > **username_0**: Yes @username_1 `{% 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](http://buildwithcraft.com/docs/plain-text-fields).
  
  But since it's a [Rich Text field](http://buildwithcraft.com/docs/rich-text-fields), it technically returns a [RichTextData](http://buildwithcraft.com/classreference/fieldtypes/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()  %}
      <h3>{{ block.heading }}</h3>
  {% endfor %}
  
  ```
  
  
  ---
  
  