2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-groupbycount

Grouped list by specified numeric amount

image

gorriecoe/silverstripe-groupbycount

Grouped list by specified numeric amount

  • Wednesday, March 7, 2018
  • by gorriecoe
  • Repository
  • 1 Watchers
  • 4 Stars
  • 39 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 144 % Grown

The README.md

Silverstripe group by count

Grouped list by specified numeric amount, (*1)

Installation

Composer is the recommended way of installing SilverStripe modules., (*2)

composer require gorriecoe/silverstripe-groupbycount

Requirements

  • silverstripe/cms ^4.0

Maintainers

Usage

Here is a standard list of links, (*3)

<% if Links %>
    <ul>
        <% loop Links %>
            <li>
                <a href="$Link">$Title</a>
            </li>
        <% end_loop %>
    </ul>
<% end_if %>

Lets say we have 5 links and want to group them in groups of 2., (*4)

<% if Links %>
    <% loop Links.GroupByCount(2) %>
        <ul>
            <% loop Items %>
                <li>
                    <a href="$Link">$Title</a>
                </li>
            <% end_loop %>
        </ul>
    <% end_loop %>
<% end_if %>

Output, (*5)

<ul>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
</ul>
<ul>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
</ul>
<ul>
    <li>
        <a href="#">title</a>
    </li>
</ul>

Now lets say we have 8 links and want group them so that the first group has 2 links, the second group has 3 and third has 1 then repeat this pattern., (*6)

<% if Links %>
    <% loop Links.GroupByCount(2,3,1) %>
        <ul>
            <% loop Items %>
                <li>
                    <a href="$Link">$Title</a>
                </li>
            <% end_loop %>
        </ul>
    <% end_loop %>
<% end_if %>

Output, (*7)

<ul>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
</ul>
<ul>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
</ul>
<ul>
    <li>
        <a href="#">title</a>
    </li>
</ul>
<ul>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
</ul>

Finally lets say we have 11 links and the first group will have 2 links while all groups remaining will have 3., (*8)

<% if Links %>
    <% loop Links.GroupByCount(2,3__) %>
        <ul>
            <% loop Items %>
                <li>
                    <a href="$Link">$Title</a>
                </li>
            <% end_loop %>
        </ul>
    <% end_loop %>
<% end_if %>

Output, (*9)

<ul>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
</ul>
<ul>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
</ul>
<ul>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
</ul>
<ul>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
    <li>
        <a href="#">title</a>
    </li>
</ul>

Count vs MaxCount

Within each group is $MaxCount which returns the defined count for that group. This is different from $Count which returns the actual count for that group., (*10)

The Versions

07/03 2018

dev-master

9999999-dev http://github.com/gorriecoe/silverstripe-groupbycount

Grouped list by specified numeric amount

  Sources   Download

BSD-3-Clause

The Requires

 

by Gorrie Coe

silverstripe list group

07/03 2018

1.0.0

1.0.0.0 http://github.com/gorriecoe/silverstripe-groupbycount

Grouped list by specified numeric amount

  Sources   Download

BSD-3-Clause

The Requires

 

by Gorrie Coe

silverstripe list group