<p>Craft adds those extra elements to each array of table cells only if there's column handles defined in your Table Field.</p>

<p>This allows you to not only access a cell's value via <code>row.col1</code>, <code>row.col2</code>, etc. but also using the columns handle, e.g. <code>row.price</code>.</p>

<p>If you don't want to use this feature or programatically loop the cells, <strong>don't define column handles!</strong></p>

CC BY-SA 3.0
2015-02-24T12:40:19.853Z
2015-02-24T12:45:57.267Z
2015-02-24T12:45:57.267Z
carlcs
<p>I suppose in your example <code>codePoints</code> is the actual Table field.</p>

<p>In order to output the table rows, the template should look like this:</p>

<pre><code>{% if block.codePoints | length %}
    &lt;ul&gt;
    {% for row in block.codePoints %}
         {# Assuming 'text' is the column handle of the text field #}
        &lt;li&gt;{{ row.text }}&lt;/li&gt; 
    {% endfor %}
    &lt;/ul&gt;
{% endif %}
</code></pre>

<p>You get a double output because every row contains an array containing each table field twice, it looks like this:</p>

<pre><code>array(2) { ["col1"]=&gt; string(4) "Some" ["text"]=&gt; string(4) "Some" }
</code></pre>

<p>That's why when loop over <code>items</code> you get every text twice.</p>

<p>I hope this helps.</p>

CC BY-SA 3.0
2014-07-01T18:48:25.990Z
Thank you Mario - that did it. How did you output that array?
Caroline from Aquarian
CC BY-SA 3.0
2014-07-01T19:31:29.993Z
I activated devMode and in my template I used `{{ dump(row) }}`
Mario
CC BY-SA 3.0
2014-07-01T18:33:44.963Z
2016-04-14T08:20:51.180Z
2016-04-14T08:20:51.180Z
Mario
<p>I have set up a <a href="http://buildwithcraft.com/docs/matrix-fields" rel="nofollow">Matrix field</a> with three blocks, each contains a <a href="http://buildwithcraft.com/docs/table-fields" rel="nofollow">Table field</a>.</p>

<p>Each table has one column - a single line text field.</p>

<p>When I call these tables into the template with this code, each row is echoed twice:</p>

<pre class="lang-html prettyprint-override"><code>{% for block in entry.projectFacts.limit(3) %}
    &lt;div class="panel panel-default"&gt;
    {% switch block.type %}
        {% case 'code' %}
            {% if block.codePoints | length %}
                &lt;ul&gt;
                    {% for items in block.codePoints %}

                        /* Outputs "Array" */
                        {{ items }}

                        {% for wtf in items %}
                            /* Outputs identical content &amp; wrapper twice */
                            &lt;li&gt;{{ wtf }}&lt;/li&gt;
                        {% endfor %}

                    {% endfor %}
                &lt;/ul&gt;
            {% endif %}
    &lt;/div&gt;
{% endfor %}
</code></pre>

<p>I'd be delighted if someone were able to point out what I need to do differently.</p>

<templating><forloop><table-field>
How to correctly output a Table Field?
# How to correctly output a Table Field?

(Asked by: username_0 on 2014-07-01)

I have set up a Matrix field with three blocks, each contains a Table field.
Each table has one column - a single line text field.
When I call these tables into the template with this code, each row is echoed twice:
{% for block in entry.projectFacts.limit(3) %}
    
    {% switch block.type %}
        {% case 'code' %}
            {% if block.codePoints | length %}
                
                    {% for items in block.codePoints %}

                        /* Outputs "Array" */
                        {{ items }}

                        {% for wtf in items %}
                            /* Outputs identical content & wrapper twice */
                            {{ wtf }}
                        {% endfor %}

                    {% endfor %}
                
            {% endif %}
    
{% endfor %}

I'd be delighted if someone were able to point out what I need to do differently.

**Tags:** templating, forloop, table-field


---

## 2 answers

### Answer by username_2 on 2014-07-01. Score: 11 | Accepted answer

I suppose in your example codePoints is the actual Table field.
In order to output the table rows, the template should look like this:
{% if block.codePoints | length %}
    
    {% for row in block.codePoints %}
         {# Assuming 'text' is the column handle of the text field #}
        {{ row.text }} 
    {% endfor %}
    
{% endif %}

You get a double output because every row contains an array containing each table field twice, it looks like this:
array(2) { ["col1"]=> string(4) "Some" ["text"]=> string(4) "Some" }

That's why when loop over items you get every text twice.
I hope this helps.

> **Comments:**
> **username_0**: Thank you username_2 - that did it. How did you output that array?  
> **username_2**: I activated devMode and in my template I used `{{ dump(row) }}`  

---

### Answer by username_1 on 2015-02-24. Score: 6

Craft adds those extra elements to each array of table cells only if there's column handles defined in your Table Field.

This allows you to not only access a cell's value via `row.col1`, `row.col2`, etc. but also using the columns handle, e.g. `row.price`.

If you don't want to use this feature or programatically loop the cells, **don't define column handles!**


---

