Selection
class Selection (View source)
The Selection class holds all methods to filter and sort the collection of pages and return them as a new selection.
Every instance can return a filtered and sorted array of pages without hurting the original Automad object. That means the Automad class object has to be created only once. To get multiple different (sorted and filtered) collections, this class can be used by just passing the collection array.
All the filter function directly modify $this->selection. After all modifications to that selection, it can be returned once by $this->getSelection().
Methods
Pass a set of pages to $this->selection excluding all hidden pages.
Exclude the current page from the selection.
Remove a page from the selection.
Return the array with the selected (filtered and sorted) pages.
Collect all pages along a given URL.
Filter $this->selection by relative url of the parent page.
Filter $this->selection by tag.
Filter $this->selection by template. A regex can be used as filter string.
Filter $this->selection by multiple keywords (a search string), if $str is not empty.
Filter out the non-hidden neighbors (previous and next page) to the passed URL.
Filter all pages having one or more tag in common with $Page. If there are not tags defined for the passed page, the selection will be an empty array. (no tags = no related pages)
While iterating a set of variable/regex combinations in $options, all pages where a given variable is not matching its assigned regex are removed from the selection.
Sorts $this->selection based on a sorting options string.
Details
at line 78
__construct(array $pages)
Pass a set of pages to $this->selection excluding all hidden pages.
at line 89
excludeCurrent()
Exclude the current page from the selection.
at line 119
excludePage(string $url)
Remove a page from the selection.
at line 138
array
getSelection(boolean $excludeHidden = true, boolean $excludeCurrent = false, integer $offset = 0, integer $limit = NULL)
Return the array with the selected (filtered and sorted) pages.
at line 159
filterBreadcrumbs(string $url)
Collect all pages along a given URL.
at line 201
filterByParentUrl(string $parent)
Filter $this->selection by relative url of the parent page.
at line 223
filterByTag(string $tag)
Filter $this->selection by tag.
at line 252
filterByTemplate(string $regex)
Filter $this->selection by template. A regex can be used as filter string.
For example passing 'page|home' as parameter will include all pages with a template that contains 'page' or 'home' as substrings.
at line 277
filterByKeywords(string $str)
Filter $this->selection by multiple keywords (a search string), if $str is not empty.
at line 325
filterPrevAndNextToUrl(string $url)
Filter out the non-hidden neighbors (previous and next page) to the passed URL.
$this->selection only holds two pages after completion with the keys ['prev'] and ['next'] instead of the URL-key. If there is only one page in the array (has no siblings), the selection will be empty. For two pages, it will only contain the ['next'] page. For more than two pages, both neighbors will be set in the selection.
at line 384
filterRelated(object $Page)
Filter all pages having one or more tag in common with $Page. If there are not tags defined for the passed page, the selection will be an empty array. (no tags = no related pages)
at line 419
match(array $options)
While iterating a set of variable/regex combinations in $options, all pages where a given variable is not matching its assigned regex are removed from the selection.
at line 461
sortPages(string $options = false)
Sorts $this->selection based on a sorting options string.
The option string consists of multiple pairs of a data key and a sort order, separated by a comma like this: $Selection->sortPages('date desc, title asc') The above example will sort first all pages in the selection by 'date' (descending) and then by 'title' (ascending).
Valid values for the order are 'asc' and 'desc'.
In case a sort order is missing in a key/order combination, the 'asc' is used as a fallback.