Answers.Body: <p>If I understand you correctly this should do the job:</p>
  
  <pre><code>{% if albumCd|length &gt; 0 or singleCd|length &gt; 0  %}
      &lt;button class="filt btn" type="button" data-filter=".CD"&gt;CD&lt;/button&gt;
  {% endif %}
  </code></pre>
  
  <p>.</p>
  
  <p>Also check out Twig docs:</p>
  
  <ul>
  <li><a href="http://twig.sensiolabs.org/doc/tags/if.html" rel="nofollow">if-statement</a></li>
  <li><a href="http://twig.sensiolabs.org/doc/templates.html#comparisons" rel="nofollow">comparison operators</a></li>
  <li><a href="http://twig.sensiolabs.org/doc/filters/index.html" rel="nofollow">Filters</a></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T20:27:31.797Z
Answers.Text: Awesome thanks that's exactly what I couldn't find how to do.
Answers.UserDisplayName: julzmon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T01:08:53.603Z
Answers.Text: Is the "> 0" necessary? I though usually just the length will work because it would be 0?
Answers.UserDisplayName: julzmon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T09:04:18.280Z
Answers.Text: That would work just as well, I just wanted to make it as clear as possible.
Answers.UserDisplayName: Victor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T19:44:22.687Z
Answers.LastActivityDate: 2014-06-26T19:44:22.687Z
Answers.UserDisplayName: Victor
Answers.Body: <p>Here's just a variation on the conditional that Victor provided that will do the same thing, might be a bit cleaner if you ever need to check several arrays:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% if albumCd|merge(singleCd)|length  %}
      &lt;button class="filt btn" type="button" data-filter=".CD"&gt;CD&lt;/button&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T01:03:46.603Z
Answers.Text: Great thanks for help. I just tried this and it gave me an error "The merge filter only works with arrays or hashes."
Answers.UserDisplayName: julzmon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T01:05:59.203Z
Answers.Text: What if you need to check more than 2 entries?
Answers.UserDisplayName: julzmon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T09:19:15.313Z
Answers.Text: albumCd should be an array of entries according to your code above. to check more than two, just continue using the merge filter to merge them.
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T20:18:21.737Z
Answers.LastActivityDate: 2014-06-27T16:26:51.670Z
Answers.LastEditDate: 2014-06-27T16:26:51.670Z
Answers.UserDisplayName: Ben Croker
Body: <p>I'm creating an isotope filter and have the following code. Could someone please help me write an if statement showing the buttons only if any of these entries have content. For instance the CD button if statement would check if the Entry "album" type "cd" and Entry "single" type "cd".</p>
  
  <pre><code>{# Albums #}
  {% set albumCd = entries.section('album').type('cd') %}
  {% set albumVinyl = entries.section('album').type('vinyl') %}
  {% set albumCassette = entries.section('album').type('cassette') %}
  {% set albumOther = entries.section('album').type('other') %}
  
  {# Singles #}
  {% set singleCd = entries.section('single').type('cd') %}
  {% set singleVinyl = entries.section('single').type('vinyl') %}
  {% set singleCassette = entries.section('single').type('cassette') %}
  {% set singleOther = entries.section('single').type('other') %}
  
  {# Collectable #}
  {% set otherVideo = entries.section('other').type('video') %}
  {% set otherMagazine = entries.section('other').type('magazine') %}
  {% set otherPrint = entries.section('other').type('print') %}
  {% set otherCollectable = entries.section('other').type('collectable') %}
  
  &lt;button class="filt btn" type="button" data-filter="*"&gt;show all&lt;/button&gt;
  &lt;button class="filt btn" type="button" data-filter=".CD"&gt;CD&lt;/button&gt;
  &lt;button class="filt btn" type="button" data-filter=".Vinyl"&gt;Vinyl&lt;/button&gt;
  &lt;button class="filt btn" type="button" data-filter=".Cassette"&gt;Cassette&lt;/button&gt;
  &lt;button class="filt btn" type="button" data-filter=".Other"&gt;Other&lt;/button&gt;
  &lt;button class="filt btn" type="button" data-filter=".Magazine"&gt;Magazine&lt;/button&gt;
  &lt;button class="filt btn" type="button" data-filter=".Print"&gt;Print&lt;/button&gt;
  &lt;button class="filt btn" type="button" data-filter=".Collectable"&gt;Collectable&lt;/button&gt;
  </code></pre>
  
Tags: <templating>
Title: How do I write an if statement to show Isotope filter button only if the Entry Section has content?
ThreadText: # How do I write an if statement to show Isotope filter button only if the Entry Section has content?
  
  (Asked by: username_0 on 2014-06-26)
  
  I'm creating an isotope filter and have the following code. Could someone please help me write an if statement showing the buttons only if any of these entries have content. For instance the CD button if statement would check if the Entry "album" type "cd" and Entry "single" type "cd".
  
  ```
  {# Albums #}
  {% set albumCd = entries.section('album').type('cd') %}
  {% set albumVinyl = entries.section('album').type('vinyl') %}
  {% set albumCassette = entries.section('album').type('cassette') %}
  {% set albumOther = entries.section('album').type('other') %}
  
  {# Singles #}
  {% set singleCd = entries.section('single').type('cd') %}
  {% set singleVinyl = entries.section('single').type('vinyl') %}
  {% set singleCassette = entries.section('single').type('cassette') %}
  {% set singleOther = entries.section('single').type('other') %}
  
  {# Collectable #}
  {% set otherVideo = entries.section('other').type('video') %}
  {% set otherMagazine = entries.section('other').type('magazine') %}
  {% set otherPrint = entries.section('other').type('print') %}
  {% set otherCollectable = entries.section('other').type('collectable') %}
  
  <button class="filt btn" type="button" data-filter="*">show all</button>
  <button class="filt btn" type="button" data-filter=".CD">CD</button>
  <button class="filt btn" type="button" data-filter=".Vinyl">Vinyl</button>
  <button class="filt btn" type="button" data-filter=".Cassette">Cassette</button>
  <button class="filt btn" type="button" data-filter=".Other">Other</button>
  <button class="filt btn" type="button" data-filter=".Magazine">Magazine</button>
  <button class="filt btn" type="button" data-filter=".Print">Print</button>
  <button class="filt btn" type="button" data-filter=".Collectable">Collectable</button>
  
  ```
  
  **Tags:** templating
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-06-26. Score: 2 | Accepted answer
  
  If I understand you correctly this should do the job:
  
  ```
  {% if albumCd|length > 0 or singleCd|length > 0  %}
      <button class="filt btn" type="button" data-filter=".CD">CD</button>
  {% endif %}
  
  ```
  
  .
  
  Also check out Twig docs:
  
  * [if-statement](http://twig.sensiolabs.org/doc/tags/if.html)
  * [comparison operators](http://twig.sensiolabs.org/doc/templates.html#comparisons)
  * [Filters](http://twig.sensiolabs.org/doc/filters/index.html)
  
  > **Comments:**
  > **username_0**: Awesome thanks that's exactly what I couldn't find how to do.  
  > **username_0**: Is the "> 0" necessary? I though usually just the length will work because it would be 0?  
  > **username_1**: That would work just as well, I just wanted to make it as clear as possible.  
  
  ---
  
  ### Answer by username_2 on 2014-06-26. Score: 3
  
  Here's just a variation on the conditional that username_1 provided that will do the same thing, might be a bit cleaner if you ever need to check several arrays:
  
  ```twig
  {% if albumCd|merge(singleCd)|length  %}
      <button class="filt btn" type="button" data-filter=".CD">CD</button>
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: Great thanks for help. I just tried this and it gave me an error "The merge filter only works with arrays or hashes."  
  > **username_0**: What if you need to check more than 2 entries?  
  > **username_2**: albumCd should be an array of entries according to your code above. to check more than two, just continue using the merge filter to merge them.  
  
  ---
  
  