<p>I got this to work with the following:</p>

<pre><code>{% set allCharges = craft.charge.charges.limit(5) %}
{% set charges = allCharges|group("dateCreated|date('F')") %}

{% for month, details in charges %}
    &lt;div&gt;   
        {{ month }}

        {% for detail in details %}
            &lt;p&gt;{{detail.id}}{{detail.customerName}}&lt;/p&gt;
        {% endfor %}
    &lt;/div&gt;
{% endfor %}
</code></pre>

<p>Two things to note: the group filter was applied to the results of the Charges query, rather than applying it to the query itself; the second issue is that the Charge model contains sub-models,which will require an inner loop. </p>

CC BY-SA 3.0
2018-01-06T19:08:33.917Z
2018-01-08T00:16:10.493Z
2018-01-08T00:16:10.493Z
Roi Agneta
<p>Has anyone had success using the Group filter with Squarebit Charge? </p>

<p>I tried a few different approaches, in each case getting array errors. Here is code:</p>

<pre><code>{% set allCharges = craft.charge.charges.limit(3)|group('cardName') %}
</code></pre>

<p>{% for cardName, details in allCharges %}</p>

<pre><code>{{ cardName }}

{% for details in allCharges %} 
    {{ details.dateCreated }}...and more fields
{% endfor %}
</code></pre>

<p>{% endfor %}</p>

<p>This throws an error message <em>"Key "dateCreated" for array with keys "0" does not exist."</em> </p>

<p>If I dump(details) I see an array that looks like all the fields you would expect, including "dateCreated"</p>

<p>Any help would be appreciated!</p>

CC BY-SA 3.0
2018-01-06T00:14:32.253Z
Is there a certain reason why you loop twice?
Robin Schambach
<plugin-charge><group>
Using the Group filter with Squarebit Charge plugin
# Using the Group filter with Squarebit Charge plugin

(Asked by: username_0 on 2018-01-05)

Has anyone had success using the Group filter with Squarebit Charge? 
I tried a few different approaches, in each case getting array errors. Here is code:
{% set allCharges = craft.charge.charges.limit(3)|group('cardName') %}

{% for cardName, details in allCharges %}
{{ cardName }}

{% for details in allCharges %} 
    {{ details.dateCreated }}...and more fields
{% endfor %}

{% endfor %}
This throws an error message "Key "dateCreated" for array with keys "0" does not exist." 
If I dump(details) I see an array that looks like all the fields you would expect, including "dateCreated"
Any help would be appreciated!

**Tags:** plugin-charge, group
> **Comments:**
> **username_1**: Is there a certain reason why you loop twice?  

---

## 1 answers

### Answer by username_0 on 2018-01-06. Score: 1

I got this to work with the following:
{% set allCharges = craft.charge.charges.limit(5) %}
{% set charges = allCharges|group("dateCreated|date('F')") %}

{% for month, details in charges %}
       
        {{ month }}

        {% for detail in details %}
            {{detail.id}}{{detail.customerName}}
        {% endfor %}
    
{% endfor %}

Two things to note: the group filter was applied to the results of the Charges query, rather than applying it to the query itself; the second issue is that the Charge model contains sub-models,which will require an inner loop.


---

