Answers.Body: <p>Your problem is a <a href="https://en.wikipedia.org/wiki/Scope_(computer_science)" rel="nofollow">scoping</a> issue. You've defined <code>theUrl</code> inside the scope of a <code>for</code> loop, so it only ever lives inside of that loop.</p>
  
  <p>You can do this to have it exist outside of the loop, too.</p>
  
  <pre><code>{% set theUrl = '' %}
  
  {% for item in entry.customerLogoBarUrl.limit(1) %}
      {% set theUrl = item.url %}
  {% endfor %}
  
  {% for item in entry.customerLogoBar %}
      {% for asset in item.logo %}
          &lt;a href="{{ theUrl }}"&gt;&lt;img src="{{ asset.url() }}"&gt;&lt;/a&gt;
      {% endfor %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-13T19:01:00.643Z
Answers.Text: I have to define `{{ the Url }}` prior to looping through the assets field, as it comes from a different field.
Answers.UserDisplayName: 4midori
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-13T20:31:52.377Z
Answers.Text: Ohh... so your 2nd example isn't a replacement of your first.  It's in addition to it.  My bad, will update answer.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-13T18:23:04.377Z
Answers.LastActivityDate: 2016-07-14T20:10:43.907Z
Answers.LastEditDate: 2016-07-14T20:10:43.907Z
Answers.UserDisplayName: Brad Bell
Body: <p>I have an entries field called 'customerLogoBarUrl'. It contains one entry. So I can do this:</p>
  
  <pre><code>{% for item in entry.customerLogoBarUrl.limit(1) %}
    {% set theUrl = item.url %}
  {% endfor %}
  </code></pre>
  
  <p>But then I need to output that variable inside an assets loop:</p>
  
  <pre><code>{% for item in entry.customerLogoBar %}
    {% for asset in item.logo %}
      &lt;a href="{{ theUrl }}"&gt;&lt;img src="{{ asset.url() }}"&gt;&lt;/a&gt;
    {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>This yields <em>theUrl doesn't exist</em>.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-13T18:24:51.340Z
Comments.Text: A few questions: Is there a reason you're using an Entries field (customerLogoBarUrl ) to define a URL and not something like a text field? In your 2nd example, is `customerLogoBar` supposed to be `customerLogoBarUrl` or do you have two fields? If the latter, what type of field is `customerLogoBar`?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-13T18:59:48.467Z
Comments.Text: @BradBell I'm using an entries field in `customerLogoBarUrl` because I need to create a relationship to the entry. `customerLogoBar` is a separate assets field.
Comments.UserDisplayName: 4midori
Tags: <assets><variable><forloop><set>
Title: How do I make my variable available inside an assets loop?
ThreadText: # How do I make my variable available inside an assets loop?
  
  (Asked by: username_0 on 2016-07-13)
  
  I have an entries field called 'customerLogoBarUrl'. It contains one entry. So I can do this:
  
  ```
  {% for item in entry.customerLogoBarUrl.limit(1) %}
    {% set theUrl = item.url %}
  {% endfor %}
  
  ```
  
  But then I need to output that variable inside an assets loop:
  
  ```
  {% for item in entry.customerLogoBar %}
    {% for asset in item.logo %}
      <a href="{{ theUrl }}"><img src="{{ asset.url() }}"></a>
    {% endfor %}
  {% endfor %}
  
  ```
  
  This yields *theUrl doesn't exist*.
  
  **Tags:** assets, variable, forloop, set
  
  > **Comments:**
  > **username_1**: A few questions: Is there a reason you're using an Entries field (customerLogoBarUrl ) to define a URL and not something like a text field? In your 2nd example, is `customerLogoBar` supposed to be `customerLogoBarUrl` or do you have two fields? If the latter, what type of field is `customerLogoBar`?  
  > **username_0**: @username_1 I'm using an entries field in `customerLogoBarUrl` because I need to create a relationship to the entry. `customerLogoBar` is a separate assets field.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-07-13. Score: 3 | Accepted answer
  
  Your problem is a [scoping](https://en.wikipedia.org/wiki/Scope_(computer_science)) issue. You've defined `theUrl` inside the scope of a `for` loop, so it only ever lives inside of that loop.
  
  You can do this to have it exist outside of the loop, too.
  
  ```
  {% set theUrl = '' %}
  
  {% for item in entry.customerLogoBarUrl.limit(1) %}
      {% set theUrl = item.url %}
  {% endfor %}
  
  {% for item in entry.customerLogoBar %}
      {% for asset in item.logo %}
          <a href="{{ theUrl }}"><img src="{{ asset.url() }}"></a>
      {% endfor %}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: I have to define `{{ the Url }}` prior to looping through the assets field, as it comes from a different field.  
  > **username_1**: Ohh... so your 2nd example isn't a replacement of your first.  It's in addition to it.  My bad, will update answer.  
  
  ---
  
  