<p>The <code>contains</code> filter works on an array of items and accepts 2 arguments, namely a key and a value to search on, as per the <a href="https://craftcms.com/docs/4.x/dev/filters.html#contains" rel="nofollow noreferrer">docs</a>. So the <code>contains</code> filter would be useful, for example, to check whether one or more entries in an array of entries contains a <code>t</code> in their intro.</p>
<p>If I’m understanding your question correctly, you want to check whether a string contains a value, in which case you can use the <code>in</code> <a href="https://twig.symfony.com/doc/3.x/templates.html#containment-operator" rel="nofollow noreferrer">containment operator</a>.</p>
<pre><code>{% if 't' in entry.intro %}
    {# ... #}
{% endif %} 
</code></pre>

CC BY-SA 4.0
2023-03-08T16:08:54.513Z
Thank you so much!
Megan
CC BY-SA 4.0
2023-03-08T15:15:58.083Z
2023-03-08T22:32:59.273Z
2023-03-08T22:32:59.273Z
Ben Croker
<p>I am trying to use a conditional on an entry detail page to show a section only if a certain field contains a &quot;t&quot; in it. This is what I have but it doesn't appear to be working no matter what I have tried. In this case the &quot;t&quot; will always be a part of a greater string (product ID).</p>
<pre><code>{% if entry.intro|contains('*t*') %}
  &lt;p&gt;TEST&lt;/p&gt;
{% endif %} 
</code></pre>
<p>I feel like this is so straightforward, but I'm just missing it! Thanks in advance for your help.</p>

<conditional><contains>
Using "contains" to find a string within an entry
# Using "contains" to find a string within an entry

(Asked by: username_0 on 2023-03-08)

I am trying to use a conditional on an entry detail page to show a section only if a certain field contains a "t" in it. This is what I have but it doesn't appear to be working no matter what I have tried. In this case the "t" will always be a part of a greater string (product ID).
{% if entry.intro|contains('*t*') %}
  TEST
{% endif %} 

I feel like this is so straightforward, but I'm just missing it! Thanks in advance for your help.

**Tags:** conditional, contains


---

## 1 answers

### Answer by username_1 on 2023-03-08. Score: 2 | Accepted answer

The contains filter works on an array of items and accepts 2 arguments, namely a key and a value to search on, as per the docs. So the contains filter would be useful, for example, to check whether one or more entries in an array of entries contains a t in their intro.
If I’m understanding your question correctly, you want to check whether a string contains a value, in which case you can use the in containment operator.
{% if 't' in entry.intro %}
    {# ... #}
{% endif %}

> **Comments:**
> **username_0**: Thank you so much!  

---

