Answers.Body: <p><code>{% for entry in craft.entries.section('sponsors').showOnHome('1') %}</code></p>
  
  <p>The <code>.showOnHome('1')</code> restricts your query to ones with the lightswitch on.</p>
  
  <p>If you wanted only the ones with the lightswitch off, you would use <code>.showOnHome('not 1')</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-03T18:02:24.523Z
Answers.Text: Thank you - I thought that was the first thing I tried, but works great!
Answers.UserDisplayName: Andrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-03T17:59:40.467Z
Answers.LastActivityDate: 2014-07-03T17:59:40.467Z
Answers.UserDisplayName: Marion Newlevant
Answers.Body: <p>While Marion’s answer is <strong>definitely</strong> the right way to go about this, since you’re new with Twig I’ll show you how you could also do this with a Twig conditional.</p>
  
  <p>You could use an <a href="http://twig.sensiolabs.org/doc/tags/if.html" rel="nofollow"><code>{% if %}</code> tag</a> to check if your showOnHome field is enabled.</p>
  
  <pre><code>&lt;ul&gt;
      {% for entry in craft.entries.section('sponsors') %}
  
          {% if entry.showOnHome %}
  
              {% for image in entry.sponsorlogo %}
                  &lt;li&gt;&lt;a href="{{ entry.getUrl }}"&gt;&lt;img src="{{ image.getUrl() }}" alt="{{ image.title }}"&lt;/a&gt;&lt;/li&gt;
              {% endfor %}
  
          {% endif %}
  
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>Hope that helps. Again, using the <code>showOnHome(1)</code> parameter on <code>craft.entries</code> query is a much better way to go, since you will be saving Craft the trouble of fetching those entries to begin with.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-03T18:14:49.813Z
Answers.LastActivityDate: 2014-07-03T18:14:49.813Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I'm pretty new to Twig and I know the level here is far above my question, but thank you in advance...</p>
  
  <p>I'm designing a site with sponsor logos on the homepage, each sponsor is an entry in a channel of sponsors. I have a lightswitch field on the entry page called 'showOnHome'.  I've tried "if" statements and conditionals in the loop, but have only got to where it shows the first entry and breaks the loop.</p>
  
  <p>The following works to get all of the entries, </p>
  
  <pre><code>&lt;ul&gt;
      {% for entry in craft.entries.section('sponsors') %}
          {% for image in entry.sponsorlogo %}
  
              &lt;li&gt;&lt;a href="{{ entry.getUrl }}"&gt;&lt;img src="{{ image.getUrl() }}" alt="{{ image.title }}"&lt;/a&gt;&lt;/li&gt;
  
          {% endfor %}
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>How do I only get entries where showOnHome == '1'?</p>
  
  <p>Thank you in advance for helping the rookie.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-04T05:17:42.393Z
Comments.Text: I think I can speak for everyone and say that the level here is at any level you need. Everyone is very happy to help and teach.
Comments.UserDisplayName: Anna_MediaGirl
Tags: <templating>
Title: Looping Entries Based on Field State
ThreadText: # Looping Entries Based on Field State
  
  (Asked by: username_0 on 2014-07-03)
  
  I'm pretty new to Twig and I know the level here is far above my question, but thank you in advance...
  
  I'm designing a site with sponsor logos on the homepage, each sponsor is an entry in a channel of sponsors. I have a lightswitch field on the entry page called 'showOnHome'. I've tried "if" statements and conditionals in the loop, but have only got to where it shows the first entry and breaks the loop.
  
  The following works to get all of the entries,
  
  ```
  <ul>
      {% for entry in craft.entries.section('sponsors') %}
          {% for image in entry.sponsorlogo %}
  
              <li><a href="{{ entry.getUrl }}"><img src="{{ image.getUrl() }}" alt="{{ image.title }}"</a></li>
  
          {% endfor %}
      {% endfor %}
  </ul>
  
  ```
  
  How do I only get entries where showOnHome == '1'?
  
  Thank you in advance for helping the rookie.
  
  **Tags:** templating
  
  > **Comments:**
  > **username_1**: I think I can speak for everyone and say that the level here is at any level you need. Everyone is very happy to help and teach.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2014-07-03. Score: 8
  
  `{% for entry in craft.entries.section('sponsors').showOnHome('1') %}`
  
  The `.showOnHome('1')` restricts your query to ones with the lightswitch on.
  
  If you wanted only the ones with the lightswitch off, you would use `.showOnHome('not 1')`
  
  > **Comments:**
  > **username_0**: Thank you - I thought that was the first thing I tried, but works great!  
  
  ---
  
  ### Answer by username_3 on 2014-07-03. Score: 3
  
  While username_2’s answer is **definitely** the right way to go about this, since you’re new with Twig I’ll show you how you could also do this with a Twig conditional.
  
  You could use an [`{% if %}` tag](http://twig.sensiolabs.org/doc/tags/if.html) to check if your showOnHome field is enabled.
  
  ```
  <ul>
      {% for entry in craft.entries.section('sponsors') %}
  
          {% if entry.showOnHome %}
  
              {% for image in entry.sponsorlogo %}
                  <li><a href="{{ entry.getUrl }}"><img src="{{ image.getUrl() }}" alt="{{ image.title }}"</a></li>
              {% endfor %}
  
          {% endif %}
  
      {% endfor %}
  </ul>
  
  ```
  
  Hope that helps. Again, using the `showOnHome(1)` parameter on `craft.entries` query is a much better way to go, since you will be saving Craft the trouble of fetching those entries to begin with.
  
  
  ---
  
  