<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>

CC BY-SA 3.0
2014-06-26T18:03:01.577Z
Thank you Ben. This is what I needed and did the trick perfectly!
Anna_MediaGirl
CC BY-SA 3.0
2014-06-26T17:59:59.003Z
2014-06-26T17:59:59.003Z
Ben Croker
<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>

CC BY-SA 3.0
2014-06-26T17:44:57.000Z
For what it's worth... Selvin taught me how to do this once but I can't remember!
Anna_MediaGirl
CC BY-SA 3.0
2014-06-26T17:53:52.550Z
Do you want this in PHP or Twig? Is this a custom table for a plugin.
Bryan Redeagle
CC BY-SA 3.0
2014-06-26T18:01:30.227Z
For Twig... This is data stored in a "Table" field type... not a custom plugin.
Anna_MediaGirl
CC BY-SA 3.0
2014-06-26T18:04:36.980Z
might be worth clarifying this in the question so it is more useful for people viewing this in future...
Ben Croker
CC BY-SA 3.0
2014-06-26T18:31:38.813Z
I edited my question.
Anna_MediaGirl
<variable><forloop>
How to create new variable from For Loop results
# 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!  

---

