Documentation · ViewHelper reference

XSD schema file | vhs 2.1.3

Iterator / SortViewHelper

Sorts an instance of ObjectStorage, an Iterator implementation, an Array or a QueryResult (including Lazy counterparts).

Can be used inline, i.e.: // iterating data which is ONLY sorted while rendering this particular loop

  • Tag usage example

    <v:iterator.sort subject="[array|\Iterator]" as="NULL" sortBy="NULL" order="'ASC'" sortFlags="'SORT_REGULAR'">
    	<!-- tag content - may be ignored! -->
    </v:iterator.sort>
  • Inline usage example

    {v:iterator.sort(subject: [array|\Iterator], as: 'NULL', sortBy: 'NULL', order: ''ASC'', sortFlags: ''SORT_REGULAR'')}

Arguments

Argument Description Type
as

Which variable to update in the TemplateVariableContainer. If left out, returns sorted data instead of updating the variable (i.e. reference or copy)

string
order

ASC, DESC, RAND or SHUFFLE. RAND preserves keys, SHUFFLE does not - but SHUFFLE is faster

string
sortBy

Which property/field to sort by - leave out for numeric sorting based on indexes(keys)

string
sortFlags

Constant name from PHP for SORT_FLAGS: SORT_REGULAR, SORT_STRING, SORT_NUMERIC, SORT_NATURAL, SORT_LOCALE_STRING or SORT_FLAG_CASE. You can provide a comma seperated list or array to use a combination of flags.

string
subject

An array or Iterator implementation to sort

array|\Iterator
Required attribute

Revision history

commit 542b285a13c3bae5b726f7ce50f8324457631c51
Author: Claus Due <*****@wildside.dk>
Date:   Sat Nov 3 16:27:35 2012 +0100

    [FEATURE] Iterator ViewHelpers
    
    Explode, Implode, First, Last, IndexOf, Next, Previous, Loop and Sort
    ViewHelpers.

commit dd7d1c55b8df0850451a06d645ab3a847a848d9f
Author: Claus Due <*****@wildside.dk>
Date:   Sun Nov 25 18:06:48 2012 +0100

    [FEATURE] Allow "RAND" and "SHUFFLE" as order, Iterator / Sort ViewHelper

commit 7621c644f8edb5ab83ae883bf322d8384db231eb
Author: Claus Due <*****@wildside.dk>
Date:   Thu Jan 17 14:21:55 2013 +0100

    [DOC] Fixed a doc comment and argument description, Iterator / Sort ViewHelper

commit c22ed3925932111f6840028d3af1b9920bd1b7ad
Author: Claus Due <*****@wildside.dk>
Date:   Thu Jan 17 14:26:43 2013 +0100

    [TASK] Don't leak template variables from Iterator/Sort when using "as" argument

commit 048fc123e977632d5bcbc628577a643c9f9c1463
Author: Benjamin Rau <*****@codearts.at>
Date:   Sat Apr 13 13:42:33 2013 +0200

    [BUGFIX] SortViewHelper to work with numberic property

commit 56efadb0f70554da0e96e2182a98a97ee5a5900d
Author: Björn Fromme <*****@bjo3rn.com>
Date:   Fri May 17 19:07:17 2013 +0200

    [TASK] Use getPropertyPath instead of getProperty
    
    This enables sorting by nested properties

commit a722a3d78779d208be576846c13ca486c6e0131f
Author: Claus Due <*****@wildside.dk>
Date:   Thu Jul 11 22:04:12 2013 +0200

    [BUGFIX] Support Lazy ObjectStorage as sortBy in iterator.sort
    
    Fixes: #267

commit 81ab178c0e0fea869a7278bf5adf891036c72896
Author: Björn Fromme <*****@bjo3rn.com>
Date:   Fri Nov 1 21:33:10 2013 +0100

    [BUGFIX] Force type integer on timestamps for natural sorting

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 f01dcaef9460306b221e5ba46f4c162c9e7e0b04
Author: Danilo Bürger <*****@hmspl.de>
Date:   Thu Feb 20 00:53:39 2014 +0100

    [BUGFIX] Removed prefix slash from namespaces class strings

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 c81d16246e5759df5fdcfffbbac4ff67db7cb883
Author: Marc Neuhaus <*****@famelo.com>
Date:   Thu Jun 26 15:54:25 2014 +0200

    [BUGFIX] Fix broken flags argument in SortViewHelper
    
    This commit fixes a bug in the SortViewHelper which prevented
    the use of combined Flags like "SORT_FLAG_CASE | SORT_STRING" to properly
    achieve caseinsensitive sorting.
    
    - use arrayFromArrayOrTraversableOrCSV to split the sortFlags
    - update documentation
    - throw exception on unknown sortFlags
    - fix sorting for empty string values

commit 11c9fb21184af736c3ae1d104d859c418da0df2d
Author: Björn Fromme <*****@bjo3rn.com>
Date:   Thu Jul 3 10:03:23 2014 +0200

    [TASK] Throw appropriate exception and add test

commit 2d55a1c13e85ca0e438f4ec3fdcd3213e3f3ea9e
Author: Claus Due <*****@namelesscoder.net>
Date:   Sat Sep 13 23:24:20 2014 +0200

    [DOC] Escape constant names in Iterator / Sort order argument
    
    Closes: #668

commit 716b251b6470782dbc09ca6e883b00cb75e5e440
Author: Claus Due <*****@namelesscoder.net>
Date:   Thu Jan 15 04:52:28 2015 +0100

    [TASK] More test ports

commit 4981055359c895f3869e5bd878293b3c15ed26e5
Author: Xaver Maierhofer <*****@xwissen.info>
Date:   Sun Jan 18 14:01:04 2015 +0100

    [TASK] CGL - Define classes, params, use imports

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

    [TASK] Reference Copyright to license.md file