The limit
function allows you to limit the number of results in a looped output. For more information on loops, please see this article on Loops.
Syntax
-
Use the vertical pipe | to separate all other functions and filters from
limit
-
Use a colon to separate the function from the numerical value of the limit (ie. the number of results)
{collectionVariable | filter:'expectedResult' | limit:numericalValue}
limit
function in conjunction with other filters or functions. If used alone on a collection without filters or functions, it will cause unexpected behaviour in that collection the next time it appears in the document. ⚠️
Example 1: Share Classes
Sample Dataset |
Share Classes:
|
---|---|
|
Limit with filter |
Input |
{#shareclasses | filter:'voting':false | limit:1}{className} {/} |
Meaning |
In the share classes collection, filtering to show only non-voting classes, list the name of the first share class appearing in the order they were input |
Output |
Special |
|
Limit with filter and sort |
Input |
{#shareclasses | filter:'voting':false | orderBy_B:'className' | limit:1}{className}{/} |
Meaning |
In the share classes collection, filtering to show only non-voting classes, list the name of the first share class as sorted by class name in ascending order |
Output |
Preferred |
Example 2: Shareholdings
Sample Dataset |
Shareholdings:
|
---|---|
|
Limit with filter and sort |
Input |
{#shareholdings | filter:'totalVotes':'!0' | orderBy_B:'!totalShares' | limit:5}{name} ({totalShares} {className} shares){/} |
Meaning |
In the shareholdings collection, filtering to show only voting classes, list the names of the top 5 shareholders by sorting the total shares held in descending order, and include the number and class of shares held in brackets. NOTE: In this example, the number of shares must be sorted in descending order using |
Output |
|