Answers.Body: <p>You could explicitly try to fetch <code>orange</code> and check whether you get a result or not:</p>
  <pre><code>{{ row.rowSettings.rowColour.slug('orange').one() ? 'orange is set' : 'orange is not set' }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-29T16:39:38.970Z
Answers.Text: YES! That's exactly what I was looking for. I knew there had to be a better way. Thank @oli  !
Answers.UserDisplayName: Adrian
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-28T14:34:43.067Z
Answers.LastActivityDate: 2020-07-28T18:31:02.403Z
Answers.LastEditDate: 2020-07-28T18:31:02.403Z
Answers.UserDisplayName: Oli
Body: <p>I am using a supertable (or matrix) to create rows.
  In each row, I have a Category Field. Multiple categories can be selected for each matrix row.
  As I loop over each row, I want to determine if the category field in that row has a specific category selected.</p>
  <p>Example:</p>
  <pre><code>Matrix Row1:
  -&gt; Colour (Category Field):
  --&gt; Red, Orange, Blue
  
  Matrix Row2:
  -&gt; Colour (Category Field):
  --&gt; Red, Blue
  </code></pre>
  <p>In the above example, in Twig, when I render out the row, I want to know if that row should be &quot;Orange&quot; or not, based on whether or not the &quot;Orange&quot; category was selected in the &quot;Colour&quot; field.</p>
  <p>I can loop through every selected category in the category field, and plaintext match against it (example below), but I wondered if there is a cleaner/simpler way to do this.</p>
  <pre><code>{% set colourFlag = false %}
  {% for class in row.rowSettings.rowColour.all() %}
      {% set colourFlag = (class == &quot;orange&quot; ? true) %}
  {% endfor %}            
  {{ colourFlag == true ? &quot;yes-orange&quot; : &quot;no-orange&quot;}}
  </code></pre>
  <p>Any advice would be grateful.</p>
  
Tags: <categories><category>
Title: Determine if entry has a specific category
ThreadText: # Determine if entry has a specific category
  
  (Asked by: username_0 on 2020-07-27)
  
  I am using a supertable (or matrix) to create rows.
  In each row, I have a Category Field. Multiple categories can be selected for each matrix row.
  As I loop over each row, I want to determine if the category field in that row has a specific category selected.
  
  Example:
  
  ```
  Matrix Row1:
  -> Colour (Category Field):
  --> Red, Orange, Blue
  
  Matrix Row2:
  -> Colour (Category Field):
  --> Red, Blue
  
  ```
  
  In the above example, in Twig, when I render out the row, I want to know if that row should be "Orange" or not, based on whether or not the "Orange" category was selected in the "Colour" field.
  
  I can loop through every selected category in the category field, and plaintext match against it (example below), but I wondered if there is a cleaner/simpler way to do this.
  
  ```
  {% set colourFlag = false %}
  {% for class in row.rowSettings.rowColour.all() %}
      {% set colourFlag = (class == "orange" ? true) %}
  {% endfor %}            
  {{ colourFlag == true ? "yes-orange" : "no-orange"}}
  
  ```
  
  Any advice would be grateful.
  
  **Tags:** categories, category
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-07-28. Score: 2 | Accepted answer
  
  You could explicitly try to fetch `orange` and check whether you get a result or not:
  
  ```
  {{ row.rowSettings.rowColour.slug('orange').one() ? 'orange is set' : 'orange is not set' }}
  
  ```
  
  > **Comments:**
  > **username_0**: YES! That's exactly what I was looking for. I knew there had to be a better way. Thank @oli  !  
  
  ---
  
  