Answers.Body: <p>Interesting. I'm not able to test this right now, but I think this should work...</p>
  
  <p>You could first loop through the results, adding them to an array as you go...</p>
  
  <pre><code>{% set guestNameValues = [] %}
  
  {% for row in partnerGuestList.guestNames %}
      {% set guestNameValues = guestNameValues|merge([row.guestName]) %}
  {% endfor %}
  </code></pre>
  
  <p>And then within your loop that displays the fields set the value as...</p>
  
  <pre><code>{{ guestNameValues[loop.index0] }}
  </code></pre>
  
  <p>That should get the corresponding name from the array you previously set.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-07T12:38:21.083Z
Answers.Text: Absolutely brilliant, works perfectly. Thanks Andrew!
Answers.UserDisplayName: darylknight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-06T11:58:57.173Z
Answers.LastActivityDate: 2016-01-06T11:58:57.173Z
Answers.UserDisplayName: Mutual
Body: <p>Sorry the question title is so random - feel free to correct it to something more succinct if you can think of one.</p>
  
  <p>Related question: <a href="https://craftcms.stackexchange.com/questions/13045/how-to-query-for-multiple-relations-with-supertable">How to query for multiple relations with SuperTable</a></p>
  
  <p>I have a front end Entry form which I'm using to create/edit an Entry which contains one field, a table called <code>guestNames</code>. The number of rows allowed in that table is set in another section's Entry (<code>event</code>). The SuperTable field in the <code>event</code> that defines how many rows are allowed is called <code>guestAllocation</code>. There two rows in that SuperTable, <code>partner</code> (Entries) and <code>places</code> (Number).</p>
  
  <p>In my front end Entry form I want to create the correct number of input fields that are allowed. I have no problem doing that with this code:</p>
  
  <pre><code>{% for row in 1..entry.guestAllocation.relatedTo(partner).first.places %}
  &lt;div class="form-group"&gt;
      &lt;label for="fields[guestNames][{{ loop.index0 }}][col1]"&gt;Name {{ loop.index }}&lt;/label&gt;
      &lt;input id="fields[guestNames][{{ loop.index0 }}][col1]" type="text" name="fields[guestNames][{{ loop.index0 }}][col1]" class="form-control"&gt;
      {% if entry is defined %}{{ errorList(entry.getErrors('fields[guestNames]')) }}{% endif %}
  &lt;/div&gt;
  {% endfor %}
  </code></pre>
  
  <p>For the purposes of this example, that could be a static number like <code>5</code>. However, I also need to provide editing functionality rather than just creating a new entry each time, so with the following line:</p>
  
  <p><code>{% if partnerGuestList|length %}&lt;input type="hidden" name="entryId" value="{{ entry.id }}"&gt;{% endif %} {# If there's a guest list for this partner, update it #}</code></p>
  
  <p>I can check if the entry exists already. Now I need to provide the correct number of input fields from <code>entry.guestAllocation.relatedTo(partner).first.places</code>, but in those input boxes, I need to provide the data from the rows in the table <code>partnerGuestList</code> <code>guestNames</code></p>
  
  <p>To get the names I need, I can query:</p>
  
  <pre><code>{% for row in partnerGuestList.guestNames %}
      {{ row.guestName }}
  {% endfor %}
  </code></pre>
  
  <p>Please comment if I can clarify any more!</p>
  
  <p><strong>Short version:</strong> How can I show data from an entry in a loop that isn't related to that entry?</p>
  
Tags: <entries><frontend>
Title: Get data from another loop from outside the current loop
ThreadText: # Get data from another loop from outside the current loop
  
  (Asked by: username_0 on 2016-01-06)
  
  Sorry the question title is so random - feel free to correct it to something more succinct if you can think of one.
  
  Related question: [How to query for multiple relations with SuperTable](https://craftcms.stackexchange.com/questions/13045/how-to-query-for-multiple-relations-with-supertable)
  
  I have a front end Entry form which I'm using to create/edit an Entry which contains one field, a table called `guestNames`. The number of rows allowed in that table is set in another section's Entry (`event`). The SuperTable field in the `event` that defines how many rows are allowed is called `guestAllocation`. There two rows in that SuperTable, `partner` (Entries) and `places` (Number).
  
  In my front end Entry form I want to create the correct number of input fields that are allowed. I have no problem doing that with this code:
  
  ```
  {% for row in 1..entry.guestAllocation.relatedTo(partner).first.places %}
  <div class="form-group">
      <label for="fields[guestNames][{{ loop.index0 }}][col1]">Name {{ loop.index }}</label>
      <input id="fields[guestNames][{{ loop.index0 }}][col1]" type="text" name="fields[guestNames][{{ loop.index0 }}][col1]" class="form-control">
      {% if entry is defined %}{{ errorList(entry.getErrors('fields[guestNames]')) }}{% endif %}
  </div>
  {% endfor %}
  
  ```
  
  For the purposes of this example, that could be a static number like `5`. However, I also need to provide editing functionality rather than just creating a new entry each time, so with the following line:
  
  `{% if partnerGuestList|length %}<input type="hidden" name="entryId" value="{{ entry.id }}">{% endif %} {# If there's a guest list for this partner, update it #}`
  
  I can check if the entry exists already. Now I need to provide the correct number of input fields from `entry.guestAllocation.relatedTo(partner).first.places`, but in those input boxes, I need to provide the data from the rows in the table `partnerGuestList` `guestNames`
  
  To get the names I need, I can query:
  
  ```
  {% for row in partnerGuestList.guestNames %}
      {{ row.guestName }}
  {% endfor %}
  
  ```
  
  Please comment if I can clarify any more!
  
  **Short version:** How can I show data from an entry in a loop that isn't related to that entry?
  
  **Tags:** entries, frontend
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-06. Score: 3 | Accepted answer
  
  Interesting. I'm not able to test this right now, but I think this should work...
  
  You could first loop through the results, adding them to an array as you go...
  
  ```
  {% set guestNameValues = [] %}
  
  {% for row in partnerGuestList.guestNames %}
      {% set guestNameValues = guestNameValues|merge([row.guestName]) %}
  {% endfor %}
  
  ```
  
  And then within your loop that displays the fields set the value as...
  
  ```
  {{ guestNameValues[loop.index0] }}
  
  ```
  
  That should get the corresponding name from the array you previously set.
  
  > **Comments:**
  > **username_0**: Absolutely brilliant, works perfectly. Thanks Andrew!  
  
  ---
  
  