Answers.Body: <p>You can use the <a href="http://twig.sensiolabs.org/doc/templates.html#variables" rel="nofollow">subscript syntax</a>:</p>
  
  <p><code>{{ entry['field' ~ loop.index] }}</code></p>
  
  <p>or the <a href="http://twig.sensiolabs.org/doc/functions/attribute.html" rel="nofollow"><code>attribute</code></a> function:</p>
  
  <p><code>{{ attribute(entry, 'field' ~ loop.index) }}</code></p>
  
  <p>The attribute function is more Twig-like in my opinion. But in this case it's only a matter of preference.</p>
  
  <p>Other examples are:</p>
  
  <p><code>{{ myArray[0] }}</code> vs. <code>{{ myArray|first }}</code><br>
  <code>{{ myString[0:1] }}</code> vs. <code>{{ myString|slice(0, 1) }}</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T10:31:04.183Z
Answers.LastActivityDate: 2015-11-07T10:42:50.830Z
Answers.LastEditDate: 2015-11-07T10:42:50.830Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>Turns out Twig has a nifty little <a href="http://twig.sensiolabs.org/doc/functions/attribute.html" rel="nofollow noreferrer">attribute function</a> that does the trick. Here's how it works:</p>
  
  <pre><code>{% for row in entry.table %}   
     {% set foo = attribute(entry, 'fieldHandle' ~ loop.index) %}
  {% endfor %}
  </code></pre>
  
  <p>Big hat tip to <a href="https://craftcms.stackexchange.com/users/57/brad-bell">Mr. Brad Bell</a> for posting the original answer in Stack Exchange. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-06T19:18:59.437Z
Answers.Text: You could also just use the [subscript syntax](http://twig.sensiolabs.org/doc/templates.html#variables): `entry['field' ~ loop.index]`.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-06T21:33:34.067Z
Answers.Text: @carlcs I thought there might be a simpler way to accomplish that. That works like a charm and, to me, is a more elegant answer. You should post it so I can vote for it!
Answers.UserDisplayName: Brett Burwell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-06T18:58:47.853Z
Answers.LastActivityDate: 2015-11-06T18:58:47.853Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: Brett Burwell
Body: <p>I'm looping through the rows of a table field and hoping to target a specific field entry based on the <code>loop.index</code>. Here's a simplified example of what that might look like:</p>
  
  <pre><code>{% for row in entry.table %}   
     {% set foo = entry.field ~ loop.index %}
  {% endfor %}
  </code></pre>
  
  <p>The doesn't work, but I’m curious if I just have the syntax wrong or if I’m thinking about this the wrong way.</p>
  
Tags: <variable><loop>
Title: Is it possible to use a loop variable to target a specific field entry?
ThreadText: # Is it possible to use a loop variable to target a specific field entry?
  
  (Asked by: username_0 on 2015-11-06)
  
  I'm looping through the rows of a table field and hoping to target a specific field entry based on the `loop.index`. Here's a simplified example of what that might look like:
  
  ```
  {% for row in entry.table %}   
     {% set foo = entry.field ~ loop.index %}
  {% endfor %}
  
  ```
  
  The doesn't work, but I’m curious if I just have the syntax wrong or if I’m thinking about this the wrong way.
  
  **Tags:** variable, loop
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-11-07. Score: 1 | Accepted answer
  
  You can use the [subscript syntax](http://twig.sensiolabs.org/doc/templates.html#variables):
  
  `{{ entry['field' ~ loop.index] }}`
  
  or the [`attribute`](http://twig.sensiolabs.org/doc/functions/attribute.html) function:
  
  `{{ attribute(entry, 'field' ~ loop.index) }}`
  
  The attribute function is more Twig-like in my opinion. But in this case it's only a matter of preference.
  
  Other examples are:
  
  `{{ myArray[0] }}` vs. `{{ myArray|first }}`  
  `{{ myString[0:1] }}` vs. `{{ myString|slice(0, 1) }}`
  
  
  ---
  
  ### Answer by username_0 on 2015-11-06. Score: 1
  
  Turns out Twig has a nifty little [attribute function](http://twig.sensiolabs.org/doc/functions/attribute.html) that does the trick. Here's how it works:
  
  ```
  {% for row in entry.table %}   
     {% set foo = attribute(entry, 'fieldHandle' ~ loop.index) %}
  {% endfor %}
  
  ```
  
  Big hat tip to [Mr. Brad Bell](https://craftcms.stackexchange.com/users/57/brad-bell) for posting the original answer in Stack Exchange.
  
  > **Comments:**
  > **username_1**: You could also just use the [subscript syntax](http://twig.sensiolabs.org/doc/templates.html#variables): `entry['field' ~ loop.index]`.  
  > **username_0**: @username_1 I thought there might be a simpler way to accomplish that. That works like a charm and, to me, is a more elegant answer. You should post it so I can vote for it!  
  
  ---
  
  