Answers.Body: <p>You can get this to work if you first escape your string using Twig <a href="http://twig.sensiolabs.org/doc/filters/escape.html" rel="nofollow"><code>escape</code></a> filter. Not exactly sure what's going on, but it'll only work for me if I make Twig double escape the string like so:</p>
  
  <pre><code>{% set strategy = 'html' %}
  {% set doubleEscapedString = entry.richTextFieldHandle|escape(strategy) %}
  {% set hasTable = '&amp;lt;/table&amp;gt;' in doubleEscapedString %}
  
  &lt;div class="{{ hasTable ? 'hasTable' : 'hasNoTable' }}"&gt;
      {{ entry.richTextFieldHandle }}
  &lt;/div&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-09T14:02:22.293Z
Answers.Text: Thanks. It looks quite messy though so I'm gonna look for a better way!
Answers.UserDisplayName: Bruce Johnson
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-06T00:01:57.090Z
Answers.LastActivityDate: 2014-12-06T00:11:43.813Z
Answers.LastEditDate: 2014-12-06T00:11:43.813Z
Answers.UserDisplayName: carlcs
Body: <p>I want to do something special in my template if there's an HTML table in the rich text field. I tried this:</p>
  
  <pre><code>{% if "&lt;/table&gt;" in entry.richTextFieldHandle %}
  </code></pre>
  
  <p>but it doesn't work. How can I do this? Or can you think of a better way?</p>
  
  <p>Thanks.</p>
  
Tags: <templating><richtext>
Title: How to check for an HTML element in a rich text field?
ThreadText: # How to check for an HTML element in a rich text field?
  
  (Asked by: username_0 on 2014-12-05)
  
  I want to do something special in my template if there's an HTML table in the rich text field. I tried this:
  
  ```
  {% if "</table>" in entry.richTextFieldHandle %}
  
  ```
  
  but it doesn't work. How can I do this? Or can you think of a better way?
  
  Thanks.
  
  **Tags:** templating, richtext
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-12-06. Score: 2 | Accepted answer
  
  You can get this to work if you first escape your string using Twig [`escape`](http://twig.sensiolabs.org/doc/filters/escape.html) filter. Not exactly sure what's going on, but it'll only work for me if I make Twig double escape the string like so:
  
  ```
  {% set strategy = 'html' %}
  {% set doubleEscapedString = entry.richTextFieldHandle|escape(strategy) %}
  {% set hasTable = '&lt;/table&gt;' in doubleEscapedString %}
  
  <div class="{{ hasTable ? 'hasTable' : 'hasNoTable' }}">
      {{ entry.richTextFieldHandle }}
  </div>
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks. It looks quite messy though so I'm gonna look for a better way!  
  
  ---
  
  