This document provides a complete reference for all PAD data handling functions.
Data handling functions transform data arrays before they are rendered in templates. They are applied as options on PAD tags:
{tagName sort="field" first="5" reverse}
Multiple handlers can be combined and are applied in sequence.
Sorts data by one or more fields with configurable direction and sort type.
{data sort}
{data sort="fieldName"}
{data sort="fieldName ASC"}
{data sort="fieldName DESC"}
{data sort="field1 ASC; field2 DESC"}
Parameters:
TRUE or empty - Sort by all fieldsfieldName - Sort by single field (ascending)fieldName ASC - Sort ascendingfieldName DESC - Sort descending;Sort Type Flags:
NUMERIC - Compare as numbersSTRING - Compare as stringsNATURAL - Natural order sortingLOCALE_STRING - Locale-aware string comparisonREGULAR - Standard comparisonExamples:
{users sort="name"}
{users sort="age DESC"}
{users sort="department ASC; name ASC"}
{products sort="price NUMERIC DESC"}
{files sort="name NATURAL ASC"}
Implementation: Uses array_multisort() for efficient multi-column sorting.
Reverses the order of data array.
{data reverse}
Parameters: None (boolean flag)
Example:
{users sort="date" reverse}
{-- Sort by date then reverse for newest first --}
Implementation: Uses array_reverse().
Randomly shuffles all elements.
{data shuffle}
Parameters: None (boolean flag)
Example:
{quotes shuffle first="1"}
{-- Get one random quote --}
Implementation: Uses PHP shuffle().
Selects random elements with advanced options.
{data random}
{data random="5"}
{data random="3" orderly duplicates}
Parameters:
random - Number of random items to select (default: all)orderly - Keep original order of selected itemsduplicates - Allow duplicate selectionsExamples:
{products random="4"}
{-- Select 4 random products --}
{users random="3" orderly}
{-- Select 3 random users, maintain their original order --}
{colors random="10" duplicates}
{-- Select 10 colors, allowing repeats --}
Implementation: Uses pqRandom() function.
Gets the first N elements.
{data first}
{data first="5"}
Parameters:
TRUE or 1 - Get first elementExamples:
{news first="3"}
{-- Show first 3 news items --}
{users sort="score DESC" first="10"}
{-- Top 10 users by score --}
Implementation: Uses array_slice($data, 0, $count).
Gets the last N elements.
{data last}
{data last="5"}
Parameters:
TRUE or 1 - Get last elementExamples:
{logs last="20"}
{-- Show last 20 log entries --}
{orders sort="date" last="5"}
{-- Last 5 orders --}
Implementation: Uses array_slice($data, -$count).
Gets a specific row by number.
{data row="3"}
Parameters:
Example:
{users row="1"}
{-- Get first user --}
Implementation: Uses padHandGo() with start=end.
Paginates data into pages.
{data page="1" rows="10"}
{data page="2" rows="25"}
Parameters:
page - Page number (1-based, default: 1)rows - Items per page (default: 10)Calculation:
Examples:
{users page="1" rows="20"}
{-- First 20 users --}
{products page="3" rows="12"}
{-- Products 25-36 (page 3 with 12 per page) --}
Gets a specific number of rows (shorthand for pagination).
{data rows="10"}
Parameters:
Behavior:
page is not set, triggers pagination with default page 1start is set, limits rows from that positionend is set, calculates start based on end - rowsExample:
{users rows="5"}
{-- First 5 users --}
{logs end="-1" rows="10"}
{-- Last 10 log entries --}
Sets the starting position for data selection.
{data start="5"}
{data start="-3"}
Parameters:
Examples:
{users start="11" rows="10"}
{-- Users 11-20 --}
{items start="-5"}
{-- Last 5 items --}
Sets the ending position for data selection.
{data end="10"}
{data end="-1"}
Parameters:
Examples:
{users start="1" end="10"}
{-- Users 1-10 --}
{items end="-2"}
{-- All items except last one --}
Extracts a portion of the array (keeps selected elements).
{data slice="5"}
{data slice="3|7"}
Parameters:
start|count - Start position and number of elementsExamples:
{items slice="10"}
{-- Keep first 10 items --}
{items slice="-5"}
{-- Keep last 5 items --}
{items slice="5|3"}
{-- Keep 3 items starting at position 5 --}
Implementation: Uses array_slice().
Removes a portion of the array (removes selected elements).
{data splice="5"}
{data splice="3|2"}
Parameters:
start|count - Start position and number to removeExamples:
{items splice="2"}
{-- Remove first 2 items --}
{items splice="-3"}
{-- Remove last 3 items --}
{items splice="5|2"}
{-- Remove 2 items starting at position 5 --}
Implementation: Uses array_splice().
Removes duplicate entries from single-field arrays.
{data dedup}
Parameters: None (boolean flag)
Behavior:
Example:
{tags dedup}
{-- Remove duplicate tags --}
Trims elements from the beginning and/or end of the array.
{data trim}
{data trim="2"}
{data trim="3" left}
{data trim="3" right}
{data trim="2" both}
Parameters:
both - Trim from both ends (default if no direction specified)left - Trim from beginning onlyright - Trim from end onlyExamples:
{items trim="1"}
{-- Remove first and last item --}
{items trim="2" left}
{-- Remove first 2 items --}
{items trim="3" right}
{-- Remove last 3 items --}
Implementation: Uses pqTruncate() function.
The negative option inverts the selection - keeping items that would normally be removed.
{data first="3" negative}
{-- Gets all items EXCEPT the first 3 --}
How it works:
Examples:
{users first="5" negative}
{-- All users except first 5 --}
{items random="3" negative}
{-- All items except 3 random ones --}
| Function | Purpose | Parameters |
|---|---|---|
sort |
Sort by field(s) | field [ASC|DESC] [; …] |
reverse |
Reverse order | (none) |
shuffle |
Random order | (none) |
random |
Random selection | count, orderly, duplicates |
first |
First N items | count |
last |
Last N items | count |
row |
Specific row | row number |
page |
Pagination | page, rows |
rows |
Row count | count |
start |
Start position | position |
end |
End position | position |
slice |
Keep portion | start|count |
splice |
Remove portion | start|count |
dedup |
Remove duplicates | (none) |
trim |
Trim ends | count, left, right, both |
Functions can be combined and are applied in sequence:
{users sort="name" first="10"}
{-- Sort by name, then get first 10 --}
{products sort="price DESC" page="1" rows="20"}
{-- Sort by price descending, paginate --}
{items shuffle first="5"}
{-- Shuffle then get first 5 (5 random items) --}
{logs sort="date DESC" dedup first="100"}
{-- Sort, deduplicate, limit to 100 --}
Handlers are processed in the order they appear in the tag parameters. Consider the order carefully:
{-- Different results: --}
{items first="10" shuffle} {-- First 10, then shuffled --}
{items shuffle first="10"} {-- Shuffled, then first 10 --}
Recommended order:
dedup - Remove duplicates firstsort - Sort the clean datashuffle / random - Randomize if neededfirst / last / page - Limit results last