Documentation · ViewHelper reference

XSD schema file | vhs 2.1.4

Iterator / ChunkViewHelper

Creates chunks from an input Array/Traversable with option to allocate items to a fixed number of chunks

  • Tag usage example

    <v:iterator.chunk count="123" fixed="1" subject="[mixed]" as="NULL" preserveKeys="1">
    	<!-- tag content - may be ignored! -->
    </v:iterator.chunk>
  • Inline usage example

    {v:iterator.chunk(count: 123, fixed: 1, subject: [mixed], as: 'NULL', preserveKeys: 1)}

Arguments

Argument Description Type
as

If specified, inserts a template variable with this name, then renders the child content, then removes the variable

string
count

The count of items per chunk or if fixed number of chunks

integer
fixed

Whether to allocate items to a fixed number of chunks or not

boolean
preserveKeys

If set to true, the original array keys will be preserved in the chunks

boolean
subject

The subject Traversable/Array instance to shift

mixed
Required attribute

Revision history

commit 4d3be347ee7fa03061baa5316bbf43f0dcbdcf4d
Author: Benjamin Rau <*****@codearts.at>
Date:   Wed Sep 25 15:14:40 2013 +0200

    [FEATURE] Chunk ViewHelper
    
    array_chunk() is a really helpful function which functionality should be available as a ViewHelper.
    
    Fx if you have an Array of pages from v:page.menu and want to allocate these links to a fixed number of container elements this would be much code without this ViewHelper.
    
    Fx we have 9 links which shall be placed in 2 containers of same count of items each, if odd the first container takes more all.
    
    Expected html markup:
    <div class="container1">
    <a>1. Link</a>
    <a>2. Link</a>
    <a>3. Link</a>
    <a>4. Link</a>
    <a>5. Link</a>
    </div>
    <div class="container2">
    <a>6. Link</a>
    <a>7. Link</a>
    <a>8. Link</a>
    <a>9. Link</a>
    </div>
    
    With this ViewHelper this is an easy task:
    {links->v:iterator.chunk(count:2,fixed:1)->v:var.set(name:'chunks')}
    <div class="container1">
    <f:for each="{chunks.0}" as="item">{item}</f:for>
    </div>
    <div class="container2">
    <f:for each="{chunks.1}" as="item">{item}</f:for>
    </div>

commit f460a749f229d94634d8b1a6c84f16e3103e2dbf
Author: Benjamin Rau <*****@codearts.at>
Date:   Wed Sep 25 15:14:40 2013 +0200

    [FEATURE] Chunk ViewHelper
    
    array_chunk() is a really helpful function which functionality should be available as a ViewHelper.
    
    Fx if you have an Array of pages from v:page.menu and want to allocate these links to a fixed number of container elements this would be much code without this ViewHelper.
    
    Fx we have 9 links which shall be placed in 2 containers of same count of items each, if odd the first container takes more all.
    
    Expected html markup:
    <div class="container1">
    <a>1. Link</a>
    <a>2. Link</a>
    <a>3. Link</a>
    <a>4. Link</a>
    <a>5. Link</a>
    </div>
    <div class="container2">
    <a>6. Link</a>
    <a>7. Link</a>
    <a>8. Link</a>
    <a>9. Link</a>
    </div>
    
    With this ViewHelper this is an easy task:
    {links->v:iterator.chunk(count:2,fixed:1)->v:var.set(name:'chunks')}
    <div class="container1">
    <f:for each="{chunks.0}" as="item">{item}</f:for>
    </div>
    <div class="container2">
    <f:for each="{chunks.1}" as="item">{item}</f:for>
    </div>

commit ed15bec7ec1450244979567f31ea9e8b7c3bc374
Author: Claus Due <*****@namelesscoder.net>
Date:   Wed Nov 6 03:21:04 2013 +0100

    [FEATURE] ViewHelperUtility for reusable methods

commit da31bad1d9bb058c072ddb5591e8ed907a1ae8e1
Author: Claus Due <*****@namelesscoder.net>
Date:   Tue Dec 31 23:08:37 2013 +0100

    [TASK] Happy new year!

commit d2e531da034976e6db1478eef5a8478595fd16fe
Author: Claus Due <*****@namelesscoder.net>
Date:   Sun Jan 5 00:45:10 2014 +0100

    [TASK] Migrate to using namespace core class names

commit 52bd6e41ccfef3d8193b350153912a9716e6a087
Author: Benjamin Rau <*****@codearts.at>
Date:   Tue Apr 1 21:09:00 2014 +0200

    [TASK] CGL compliance

commit da7677bc74f14e9a9300e4ba4487e52c3cb97642
Author: Claus Due <*****@namelesscoder.net>
Date:   Sun Apr 20 01:13:33 2014 +0200

    [TASK] Switch to namespaces

commit fc3c6cc1367bb88b6980be9ace4f0842432960e8
Author: Björn Fromme <*****@bjo3rn.com>
Date:   Wed Jul 16 17:28:03 2014 +0200

    [TASK] Ensure configured element count

commit dbed82122874111fef26792106b1614396e68f74
Author: Björn Fromme <*****@bjo3rn.com>
Date:   Sat Jul 19 21:31:34 2014 +0200

    [BUGFIX] Ensure valid arguments for array_chunk

commit 922e8592d9b7f3f78c300fec7231351542e40f1b
Author: Henning Kasch <*****@die-netzwerkstatt.de>
Date:   Mon Jul 21 17:56:44 2014 +0200

    [TASK] Add argument to preserve array keys on ChunkViewHelper

commit 8bb2fc5ee124ba19b0a0ab8e061c9a153fc4651f
Author: Xaver Maierhofer <*****@xwissen.info>
Date:   Sun Jan 18 17:56:13 2015 +0100

    [TASK] Reference Copyright to license.md file