Answers.Body: <p>I'm not 100% following your question, but it's likely a variable re-use issue.</p>
  
  <p>Basically, you're setting the variable once, and if it exists, do blah....</p>
  
  <p>Then, you're attempting to re-set that variable below.  Something goes wrong with that, but <code>entry</code> still exists at that point, so it passes the seconds test but in that second block  entry is still pointing to the data it retrieved in the first use.</p>
  
  <p>(You might find it useful to check out:
  <a href="https://straightupcraft.com/articles/testing-if-something-exists-is-defined-length-is-not-null-is-not-empty" rel="nofollow noreferrer">https://straightupcraft.com/articles/testing-if-something-exists-is-defined-length-is-not-null-is-not-empty</a></p>
  
  <p>...which has a whole lot of stuff about testing variables too)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-30T11:33:49.637Z
Answers.Text: Thanks Jeremy for your comment, as it was a re-use issue with repetition of "entry" as a variable. I made the variable names specific to the scope of each relation. That worked.
Answers.UserDisplayName: bdanchuk
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-30T15:51:53.850Z
Answers.Text: Welcome to the Craft CMS Stack Exchange, @bdanchuk! I moved your previous answer to a comment since it wasn't actually an answer. There's an [FAQ article](https://meta.stackexchange.com/questions/7931/faq-for-stack-exchange-sites) for general post guidelines if you're curious about Jeremy's earlier formatting comment or the answer-vs.-comment issue here.
Answers.UserDisplayName: Matt Stein
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-30T23:05:40.463Z
Answers.Text: Also, good practise to come back and accept the answer if it helped - other will then know in the future that the answer if helpful!
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-30T04:09:43.127Z
Answers.LastActivityDate: 2017-03-30T04:09:43.127Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>I'm try to use related entries from different channels to display content on a home page. Using the code following with "selectNews" as a entries fieldHandle in the Home Page:</p>
  
  <pre><code>  {% set entry = entry.selectNews.first() %}
    {% if entry %}   
       ...
    {% endif %}
  </code></pre>
  
  <p>This places field entries from craft section "news", the first &amp; only entry. Following that is a div with the same code, but with a new entries field and fieldHandle, "messageBanner", relating to an channel named "Banners". This second set of code fails to display anything. I see that </p>
  
  <p><code>... {{ entry }}...</code></p>
  
  <p>tested in the failed div, outside of <code>{%set entry =... endif %}</code>, prints to screen the related entry title from the previous code. How can I get this fixed and what am I missing. Pretty confused.</p>
  
  <pre><code>{% set entry = entry.selectNews.first() %}
    {% if entry %}
  ...
  &lt;div class="row"&gt; 
     {% set asset = entry.newsImage.first() %}
        {% if asset %}
         &lt;img class="col-xs-12" src=" {{ asset.url }} " alt=" News image "/&gt; 
        {% endif %}      
      &lt;/div&gt;
    &lt;/div&gt;  
  ...
  {% endif %} 
  
  
  {% set entry = entry.messageBanner.first() %}
    {% if entry %}
  
  &lt;section class="offer-stripe center"&gt;
    &lt;div class="container-fluid"&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-xs-12"&gt; 
          &lt;a href="{{ entry.bannerLink }}"&gt;
            &lt;h5&gt;&lt;span class="red"&gt; some text &lt;/span&gt;&lt;small&gt;&lt;em&gt; {{entry.bannerText}} &lt;/em&gt;&lt;/small&gt;&lt;/h5&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/section&gt;
  
  {% endif %} 
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-30T01:07:50.823Z
Comments.Text: Could you edit your question so that is has acode summary of _both_ sections of code, please.  And try and use the SE code formatting tools - https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks
Comments.UserDisplayName: Jeremy Daalder
Tags: <entries><relations>
Title: Craft entries statements failing
ThreadText: # Craft entries statements failing
  
  (Asked by: username_0 on 2017-03-30)
  
  I'm try to use related entries from different channels to display content on a home page. Using the code following with "selectNews" as a entries fieldHandle in the Home Page:
  
  ```
    {% set entry = entry.selectNews.first() %}
    {% if entry %}   
       ...
    {% endif %}
  
  ```
  
  This places field entries from craft section "news", the first & only entry. Following that is a div with the same code, but with a new entries field and fieldHandle, "messageBanner", relating to an channel named "Banners". This second set of code fails to display anything. I see that
  
  `... {{ entry }}...`
  
  tested in the failed div, outside of `{%set entry =... endif %}`, prints to screen the related entry title from the previous code. How can I get this fixed and what am I missing. Pretty confused.
  
  ```
  {% set entry = entry.selectNews.first() %}
    {% if entry %}
  ...
  <div class="row"> 
     {% set asset = entry.newsImage.first() %}
        {% if asset %}
         <img class="col-xs-12" src=" {{ asset.url }} " alt=" News image "/> 
        {% endif %}      
      </div>
    </div>  
  ...
  {% endif %} 
  
  {% set entry = entry.messageBanner.first() %}
    {% if entry %}
  
  <section class="offer-stripe center">
    <div class="container-fluid">
      <div class="row">
        <div class="col-xs-12"> 
          <a href="{{ entry.bannerLink }}">
            <h5><span class="red"> some text </span><small><em> {{entry.bannerText}} </em></small></h5></a>
        </div>
      </div>
    </div>
  </section>
  
  {% endif %} 
  
  ```
  
  **Tags:** entries, relations
  
  > **Comments:**
  > **username_1**: Could you edit your question so that is has acode summary of _both_ sections of code, please.  And try and use the SE code formatting tools - https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-03-30. Score: 2
  
  I'm not 100% following your question, but it's likely a variable re-use issue.
  
  Basically, you're setting the variable once, and if it exists, do blah....
  
  Then, you're attempting to re-set that variable below. Something goes wrong with that, but `entry` still exists at that point, so it passes the seconds test but in that second block entry is still pointing to the data it retrieved in the first use.
  
  (You might find it useful to check out:
  <https://straightupcraft.com/articles/testing-if-something-exists-is-defined-length-is-not-null-is-not-empty>
  
  ...which has a whole lot of stuff about testing variables too)
  
  > **Comments:**
  > **username_0**: Thanks username_1 for your comment, as it was a re-use issue with repetition of "entry" as a variable. I made the variable names specific to the scope of each relation. That worked.  
  > **username_2**: Welcome to the Craft CMS Stack Exchange, @username_0! I moved your previous answer to a comment since it wasn't actually an answer. There's an [FAQ article](https://meta.stackexchange.com/questions/7931/faq-for-stack-exchange-sites) for general post guidelines if you're curious about username_1's earlier formatting comment or the answer-vs.-comment issue here.  
  > **username_1**: Also, good practise to come back and accept the answer if it helped - other will then know in the future that the answer if helpful!  
  
  ---
  
  