Answers.Body: <p>I've managed to get things working but I'm not sure if there is a better way of doing this. Any feedback is welcome.</p>
  
  <p>Here's the new code.</p>
  
  <pre><code>    {# Grab all the photo entries #}
      {% set photos = entry.photoGallery.type( 'photos' ) %}
  
      {# create a blank array to merge content #}
      {% set selectedFeaturedImages = [] %}
  
      {% for block in photos %}
          {# Add Featured Images to an array #}
          {% if block.imageLocation.contains('featured') %}
              {% set selectedFeaturedImages = selectedFeaturedImages|merge([block]) %}
          {% endif %}
      {% endfor %}
  
      {% for block in selectedFeaturedImages %}
          {% if loop.first %}
          &lt;div class="row" &gt;
              &lt;div class="columns"&gt;
                  &lt;div class="slidr"&gt;
          {% endif %}
  
              {% for photo in block.photo %}
          &lt;div class="figure"&gt;&lt;a href="{{ photo.getUrl }}"&gt;&lt;img src="{{ photo.getUrl('projectHero') }}" alt=""&gt;&lt;/a&gt;
              {# Get the caption #}
              {% if block.caption|length %}
              &lt;div class="caption"&gt;{{ block.caption }}&lt;/div&gt;
              {% endif %}
          &lt;/div&gt;
              {% endfor %}
  
          {% if loop.last %}
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          {% endif %}
      {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-06T01:40:49.640Z
Answers.Text: I've marked this as the correct answer as I haven't had any feedback from anyone else and it is functioning properly.
Answers.UserDisplayName: Rheal Poirier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-03T19:49:41.103Z
Answers.LastActivityDate: 2017-01-03T19:49:41.103Z
Answers.UserDisplayName: Rheal Poirier
Answers.Body: <pre><code>{% if block.checkboxFieldHandle.contains('someChkbxValue') %}
  &lt;p&gt;Executed!&lt;/p&gt;
  {% endif %}
  </code></pre>
  
  <p>actual for Craft v2.x and v3.x</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-06T06:27:13.700Z
Answers.LastActivityDate: 2018-06-06T06:27:13.700Z
Answers.UserDisplayName: Nikolay Bronskiy
Answers.Body: <p>It looks as though you have the following line wrong:</p>
  
  <p><code>{% for block in photos if block.imageLocation.contains('featured') %}</code></p>
  
  <p>You will need to use the field name you're using to filter the Matrix block in place of <code>contains</code>. The following line will only loop through block with the <code>imageLocation</code> field set to "featured".</p>
  
  <p><code>{% for block in photos.imageLocation('featured') %}</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-03T17:03:48.777Z
Answers.Text: I had tried tried what you suggested but that gives all of the entries regardless if 'featured' is checked.
Answers.UserDisplayName: Rheal Poirier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-03T17:04:40.417Z
Answers.Text: What is the error?
Answers.UserDisplayName: Luke Pearce
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-03T17:10:23.757Z
Answers.Text: I see in the craft docs that "you can tell if the option is selected or not via `option.selected`." but I'm unsure how to make that work in the if statement.
  
  Like I mentioned in the original post. The above code works but I want to be able to hide the divs if there are no featured images.
Answers.UserDisplayName: Rheal Poirier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-03T11:37:25.633Z
Answers.LastActivityDate: 2017-01-03T11:37:25.633Z
Answers.UserDisplayName: Luke Pearce
Body: <p>I currently have checkboxes in a matrix block that allow a user to select where an image will be placed in the layout (as a featured slider image and/or in an image gallery). I've gotten the slider image to function but if, for some reason, there are no featured images I have a couple of unnecessary <code>&lt;div&gt;</code> tags. Because I am selecting only featured images from the matrix block I can not use <code>loop.first</code> and <code>loop.last</code> to move those divs in my for loop. </p>
  
  <p>I had seen an article that seems close to finding the answer to my problem here : <a href="https://craftcms.stackexchange.com/questions/8915/only-execute-twig-block-if-a-matrix-radio-has-a-certain-value">Only execute twig block if a Matrix radio has a certain value</a> but I haven't been able to make it work. </p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <pre><code>{# Add Feature Images - Slideshow #}
      {% set photos = entry.photoGallery.type( 'photos' ) %}
      {% if photos|length %}
      &lt;div class="row" &gt;
              &lt;div class="slidr"&gt;
                  {% for block in photos if block.imageLocation.contains('featured')%}
                      {# Get the photo #}
                      {% for photo in block.photo %}
                        &lt;div class="figure"&gt;
                          &lt;a href="{{ photo.getUrl }}"&gt;
                            &lt;img src="{{ photo.getUrl('projectHero') }}" alt=""&gt;
                          &lt;/a&gt;
                          {# Get the caption #}
                          {% if block.caption|length %}
                            &lt;div class="caption"&gt;{{ block.caption }}&lt;/div&gt;
                          {% endif %}
                        &lt;/div&gt;
                      {% endfor %}
                  {% endfor %}
              &lt;/div&gt;
      &lt;/div&gt;
      {% endif %}
  </code></pre>
  
  <p>I've attached a screen snapshot of my field setup.
  <a href="https://i.sstatic.net/hXE8O.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hXE8O.png" alt="screen snapshot of matrix field"></a></p>
  
Tags: <matrix><checkboxes>
Title: Only executing if a matrix checkbox has a specific value
ThreadText: # Only executing if a matrix checkbox has a specific value
  
  (Asked by: username_0 on 2017-01-03)
  
  I currently have checkboxes in a matrix block that allow a user to select where an image will be placed in the layout (as a featured slider image and/or in an image gallery). I've gotten the slider image to function but if, for some reason, there are no featured images I have a couple of unnecessary `<div>` tags. Because I am selecting only featured images from the matrix block I can not use `loop.first` and `loop.last` to move those divs in my for loop.
  
  I had seen an article that seems close to finding the answer to my problem here : [Only execute twig block if a Matrix radio has a certain value](https://craftcms.stackexchange.com/questions/8915/only-execute-twig-block-if-a-matrix-radio-has-a-certain-value) but I haven't been able to make it work.
  
  Any help would be greatly appreciated.
  
  ```
  {# Add Feature Images - Slideshow #}
      {% set photos = entry.photoGallery.type( 'photos' ) %}
      {% if photos|length %}
      <div class="row" >
              <div class="slidr">
                  {% for block in photos if block.imageLocation.contains('featured')%}
                      {# Get the photo #}
                      {% for photo in block.photo %}
                        <div class="figure">
                          <a href="{{ photo.getUrl }}">
                            <img src="{{ photo.getUrl('projectHero') }}" alt="">
                          </a>
                          {# Get the caption #}
                          {% if block.caption|length %}
                            <div class="caption">{{ block.caption }}</div>
                          {% endif %}
                        </div>
                      {% endfor %}
                  {% endfor %}
              </div>
      </div>
      {% endif %}
  
  ```
  
  I've attached a screen snapshot of my field setup.
  [![screen snapshot of matrix field](https://i.sstatic.net/hXE8O.png)](https://i.sstatic.net/hXE8O.png)
  
  **Tags:** matrix, checkboxes
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2017-01-03. Score: 1 | Accepted answer
  
  I've managed to get things working but I'm not sure if there is a better way of doing this. Any feedback is welcome.
  
  Here's the new code.
  
  ```
      {# Grab all the photo entries #}
      {% set photos = entry.photoGallery.type( 'photos' ) %}
  
      {# create a blank array to merge content #}
      {% set selectedFeaturedImages = [] %}
  
      {% for block in photos %}
          {# Add Featured Images to an array #}
          {% if block.imageLocation.contains('featured') %}
              {% set selectedFeaturedImages = selectedFeaturedImages|merge([block]) %}
          {% endif %}
      {% endfor %}
  
      {% for block in selectedFeaturedImages %}
          {% if loop.first %}
          <div class="row" >
              <div class="columns">
                  <div class="slidr">
          {% endif %}
  
              {% for photo in block.photo %}
          <div class="figure"><a href="{{ photo.getUrl }}"><img src="{{ photo.getUrl('projectHero') }}" alt=""></a>
              {# Get the caption #}
              {% if block.caption|length %}
              <div class="caption">{{ block.caption }}</div>
              {% endif %}
          </div>
              {% endfor %}
  
          {% if loop.last %}
                  </div>
              </div>
          </div>
          {% endif %}
      {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: I've marked this as the correct answer as I haven't had any feedback from anyone else and it is functioning properly.  
  
  ---
  
  ### Answer by username_1 on 2018-06-06. Score: 3
  
  ```
  {% if block.checkboxFieldHandle.contains('someChkbxValue') %}
  <p>Executed!</p>
  {% endif %}
  
  ```
  
  actual for Craft v2.x and v3.x
  
  
  ---
  
  ### Answer by username_2 on 2017-01-03. Score: 2
  
  It looks as though you have the following line wrong:
  
  `{% for block in photos if block.imageLocation.contains('featured') %}`
  
  You will need to use the field name you're using to filter the Matrix block in place of `contains`. The following line will only loop through block with the `imageLocation` field set to "featured".
  
  `{% for block in photos.imageLocation('featured') %}`
  
  > **Comments:**
  > **username_0**: I had tried tried what you suggested but that gives all of the entries regardless if 'featured' is checked.  
  > **username_2**: What is the error?  
  > **username_0**: I see in the craft docs that "you can tell if the option is selected or not via `option.selected`." but I'm unsure how to make that work in the if statement.  Like I mentioned in the original post. The above code works but I want to be able to hide the divs if there are no featured images.  
  
  ---
  
  