Answers.Body: <p>If I understood your question correctly then you should be able to do it as follows:</p>
  
  <pre><code>{% set sizes = [] %}
  
  {% for productAttribute in entry.productAttributes %}
      {% set sizes = sizes|merge([productAttribute.size]) %}
  {% endfor %}
  
  {% set sizes = sizes|join('|') %}
  </code></pre>
  
  <p>The <code>sizes</code> variable will then be a string containing the pipeline separated sizes, for example:</p>
  
  <pre><code>small|medium|large
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T18:03:01.577Z
Answers.Text: Thank you Ben. This is what I needed and did the trick perfectly!
Answers.UserDisplayName: Anna_MediaGirl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T17:59:59.003Z
Answers.LastActivityDate: 2014-06-26T17:59:59.003Z
Answers.UserDisplayName: Ben Croker
Body: <p>I need to get a list of all the "sizes" from my Table type field column. The list of sizes needs to be separated by a "|"... eg: small|medium|large</p>
  
  <p>My Table type field name is "productAttributes" and the column in that field is "size".</p>
  
  <p>How can I string together the results of a For Each loop to create a new variable with Twig? </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-26T17:44:57.000Z
Comments.Text: For what it's worth... Selvin taught me how to do this once but I can't remember!
Comments.UserDisplayName: Anna_MediaGirl
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-26T17:53:52.550Z
Comments.Text: Do you want this in PHP or Twig? Is this a custom table for a plugin.
Comments.UserDisplayName: Bryan Redeagle
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-26T18:01:30.227Z
Comments.Text: For Twig... This is data stored in a "Table" field type... not a custom plugin.
Comments.UserDisplayName: Anna_MediaGirl
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-26T18:04:36.980Z
Comments.Text: might be worth clarifying this in the question so it is more useful for people viewing this in future...
Comments.UserDisplayName: Ben Croker
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-26T18:31:38.813Z
Comments.Text: I edited my question.
Comments.UserDisplayName: Anna_MediaGirl
Tags: <variable><forloop>
Title: How to create new variable from For Loop results
ThreadText: # How to create new variable from For Loop results
  
  (Asked by: username_0 on 2014-06-26)
  
  I need to get a list of all the "sizes" from my Table type field column. The list of sizes needs to be separated by a "|"... eg: small|medium|large
  
  My Table type field name is "productAttributes" and the column in that field is "size".
  
  How can I string together the results of a For Each loop to create a new variable with Twig?
  
  **Tags:** variable, forloop
  
  > **Comments:**
  > **username_0**: For what it's worth... Selvin taught me how to do this once but I can't remember!  
  > **username_1**: Do you want this in PHP or Twig? Is this a custom table for a plugin.  
  > **username_0**: For Twig... This is data stored in a "Table" field type... not a custom plugin.  
  > **username_2**: might be worth clarifying this in the question so it is more useful for people viewing this in future...  
  > **username_0**: I edited my question.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-06-26. Score: 11 | Accepted answer
  
  If I understood your question correctly then you should be able to do it as follows:
  
  ```
  {% set sizes = [] %}
  
  {% for productAttribute in entry.productAttributes %}
      {% set sizes = sizes|merge([productAttribute.size]) %}
  {% endfor %}
  
  {% set sizes = sizes|join('|') %}
  
  ```
  
  The `sizes` variable will then be a string containing the pipeline separated sizes, for example:
  
  ```
  small|medium|large
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you Ben. This is what I needed and did the trick perfectly!  
  
  ---
  
  